.net - C# Trouble with event handlers on dieing threads -


first of main stathread , not able change without facing problems rest of code.

so, using rapi2 pull , push files between pda , computer. since there quite bit of number crunching on separate thread. first wat create remotedevicemanager , make event handler when device connects.

public void initialize()     {         _devicemanager = new remotedevicemanager();         _devicemanager.deviceconnected += deviceconnected;     } 

as can see when device connects triggers deviceconnected. class end pulling , pushing database , number work.

 private void deviceconnected(object sender, remotedeviceconnecteventargs e)         {            if (e.device == null) return;            ... (unimportant code)         } 

now problem here want run code inside deviceconnected in new thread unable access e inside new thread since initialized outside thread enter image description here

so wat tried make new thread before calling initialize.

public watcher()     {         _datathread = new thread(initialize);         _datathread.isbackground = true;         _datathread.name = "data thread";         _datathread.setapartmentstate(apartmentstate.mta);         _datathread.start();     } 

but thread dies , never fires event handler. tried many different ways make work or keep thread alive without success. hope here able give me hints.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -