c# - EventHandler doesn't fire after Thread re-creation -
With the UI thread, I create another thread using a background worker. In this thread I am using NetworkChanged eventhandler. After the connection is lost, i DoWorkEventArgs e. Cancel, close the thread Once the network is reconnected, I restart the thread using the same background. However, from this point, the event holder will no longer fire the network to disconnect or reconnect.
EventHolder's code is in test class that is starting to use the initial backwork worker.
Public Test () {NetworkChange.NetworkAvailabilityChanged + = New NetworkApplication Changed EventHandler (NetworkChange_NetworkAvailabilityChanged); } Protected Virtual Zero NetworkChange_Network Availability Change (Object Sender, Networks Avenue E.E.) {try (if available e) {iSnectionActive = true; //RemailThread} and {iSnectionActive = False; // close thread}} {} }
I have read that some events are not threads, but I do not understand from other examples what I have to do to change it. (If that is also the issue) So i What error did I give, and how should I face this problem?
Many thanks.
Edit:
Work Code:
Private Zero Background Worker_DoWork (Object Sender, DoWorkEventArgs e) {BackgroundWorker worker = Sender as BackgroundWorker; Worker.workerReportsProgress = true; worker .cancer support cancellation = true; runmodels (worker, e);}
Code to cancel DoWork:
Convert Public Nuclear Model Conversion (Bull Pre Suck) {try {if (sender == false) {m_currentworker.ReportProgress (0, "disconnected"); M_currentworker.CancelAsync (); DoWork.Cancel = true; }} Hold (exception e) {throw e; }}
These lines:
worker worker Reports progress = true; Worker Cancel worker support = true;
to be transferred in advance:
worker.RunWorkerAsync ();
They are in the wrong place. In addition, you m_currentworker.CancelAsync (); Can not use the
; It should be said from the point where you want to stop the worker. Also, in your DoWork
handler in runmodels (worker, e)
you have to cancel the worker. Cancellation
and when this flag is set to true then stop.
What is actually happening when you call CancelAsync ();
Flag cancellation payment
is set to True DoWork (...)
is your job to return as soon as possible.
Comments
Post a Comment