English 中文(简体)
WebClient: 如何取消长期搁置的吉大港山区申请?
原标题:WebClient: how to cancel a long running HTTP request?

I m using WebClient to make a request to an API that has a very long running process. But I don t actually need to know the result, I only need the process to be started.

It doesn t matter to me if the process succeeds or fails. So I want to drop the connection as soon as I have made the request.

我怎么能够放弃网络联系? 我不想等待30至60秒的答复:

var client = new WebClient();
string url = "http://example.com/SomeVeryLongRunningProcess/parameter";
client.BeginDownloadString(uri);
client.DropConnection; // how do I drop the connection before the response is received?
最佳回答

页: 1

问题回答

CancelAsync(

I suggest you to use DownloadProgressChanged event instead => you will be sure the server received your request and started to treat it.

Warning: you also need to update your server code to start returning information (HTTP headers or some text) as soon as it starts the process if this is not the case. If not, DownloadProgressChanged will start receiving information only when process is done.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签