Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
On the UI I’m creating a thread:
ConetarBiometriaThread = new Thread(new ThreadStart(ConectarBiometria));
ConetarBiometriaThread.IsBackground = true;
ConetarBiometriaThread.Start();


private void ConectarBiometria()
{
axCZKEM1 = new zkemkeeper.CZKEMClass();
try
{
bIsConnected = axCZKEM1.Connect_Net("192.168.1.201", 4370);
axCZKEM1.OnVerify += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(axCZKEM1_OnVerify);
axCZKEM1.StartIdentify();
}
catch
{ }
}


Now I need to be able to listen to axCZKEM1_OnVerify on the main thread…but I have no idea how….
Posted
Comments
Sergey Alexandrovich Kryukov 19-Oct-14 13:33pm    
If you create some thread by another thread, in what sense can it be called "main thread". The problem is very simple:

Event is invoked in an instance of some class/struct. Invocation takes place in some thread. It does not matter how you "listen" — you just add a handler in the invocation list of some event instance. The thread is determined by the thread performing invocation, so your handler will be called in that thread.

Now, you can think in terms of consequence of this fact. If this is not clear, please explain your goal and your problem, then I'll answer.

In particular, what is your thread to handle the event: UI or not? What should it do? If UI, what kind of UI (WPF, forms, anything else?)?

—SA
BillWoodruff 19-Oct-14 15:42pm    
I think this CodeProject example might help you:

http://www.codeproject.com/Articles/1280/Worker-Threads-in-C
Sergey Alexandrovich Kryukov 20-Oct-14 0:53am    
Despite of high popularity, I think it's a pretty bad article. A thread stopping procedure along, with Application.DoEvents tells the tale. I would not advice anyone to follow this article.
—SA
Ziee-M 20-Oct-14 11:23am    
I totaly agree, i used Application.DoEvents in long running process and it ends by a crash : unhandled exception.

1 solution

Why not just listen to a static event from ConectarBiometria?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900