Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>Once the main bgAgent thread exits, the HttpWebRequest will be killed. </li> <li>We should be using synchronous HttpWebRequest here, but we can't because MS took them away from gelded framework. </li> <li>We have to mimic thread-blocking behaviour using thread synchronization objects, like ManualResetEvent.</li> </ol> <pre> protected override void OnInvoke(ScheduledTask task) { var evnt = new ManualResetEvent(false);//initialize to unsignalled state (false) var request = (HttpWebRequest)WebRequest.Create(new Uri("http://foo.bar")); request.BeginGetResponse(r => { //do work here evnt.Set();//signal main thread to continue }, request); evnt.WaitOne();//block execution of main thread NotifyComplete(); return; }</pre> <p>This way neither main thread will exit not NotifyComplete will be called before you finish your work. You should make that WaitOne with a timeout (around 25 seconds) to ensure your task won't get killed and (worse) unsheduled because of 30 secs limit. This will make things much more complicated, as you'll have to protect your both threads (main and http) from messing each other up. The evnt.Close() issue is also not shown here. Main thread may close the handle before http finishes and tries to Set(). Or you can rely on garbage collection <a href="https://stackoverflow.com/questions/2234128/do-i-need-to-call-close-on-a-manualresetevent/2358158#2358158">Do I need to call Close() on a ManualResetEvent?</a></p> <p>(btw, ManualResetEvent has nothing to do with concept of C# event. It's and event in Win32 sense, from same gang as Mutex and Semaphore).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload