Call function from thread
-
Hi everybody, it's probably a stupid question but i hope someone can help me :-D . I have the following situation: A TAPIClass which gets an eventhandler (which himself gets events from the phone) I created a class CPhone which should store the instance of the TAPIClass. In the constructor i create the TAPIClass instance and initialize it. The CPhone instances are created into a thread which is created this way:
new Thread(new ParameterizedThreadStart(TelSignalThread));
where TelSignalThread is a static function of the Main-Form which creates an instance of the CPhone class
public static void TelSignalThread(object param)
{
MainForm Win = (MainForm)param;CPhone tel = new CPhone(Win);
while(Win->Running)
{
Threading.Sleep(10);
}
}My question is, how is it possible to call a function from CPhone from out the MainForm? Call the GUI from out the Thread works with Invoke.
Edit: Or is it the best way to derive my CPhone-Class from the class Thread and to add class-members to the CPhone class? Does exists a PhoneThreadInst->Invoke(...); ?
Before i created this thread and the CPhone-Class, i had the TAPIClass into the MainForm, without a special thread and it worked great. Then i needed to open a new window from a button-click during a phone call. This provokes sometimes a event-lost from the TAPIClass , and a missing "hang-up Event" disturbes my whole appliction :sigh: Big thanks for any help :) -
Hi everybody, it's probably a stupid question but i hope someone can help me :-D . I have the following situation: A TAPIClass which gets an eventhandler (which himself gets events from the phone) I created a class CPhone which should store the instance of the TAPIClass. In the constructor i create the TAPIClass instance and initialize it. The CPhone instances are created into a thread which is created this way:
new Thread(new ParameterizedThreadStart(TelSignalThread));
where TelSignalThread is a static function of the Main-Form which creates an instance of the CPhone class
public static void TelSignalThread(object param)
{
MainForm Win = (MainForm)param;CPhone tel = new CPhone(Win);
while(Win->Running)
{
Threading.Sleep(10);
}
}My question is, how is it possible to call a function from CPhone from out the MainForm? Call the GUI from out the Thread works with Invoke.
Edit: Or is it the best way to derive my CPhone-Class from the class Thread and to add class-members to the CPhone class? Does exists a PhoneThreadInst->Invoke(...); ?
Before i created this thread and the CPhone-Class, i had the TAPIClass into the MainForm, without a special thread and it worked great. Then i needed to open a new window from a button-click during a phone call. This provokes sometimes a event-lost from the TAPIClass , and a missing "hang-up Event" disturbes my whole appliction :sigh: Big thanks for any help :)If you just want to call a function in CPhone form outside the class, you can expose the fucntion by making it static. Why do you want to use a thread to create the TAPICalss?? Did you try to use the BackgroundWorker threads ?? Missing of the event is very uncertain , dont know why it occures .
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
-
If you just want to call a function in CPhone form outside the class, you can expose the fucntion by making it static. Why do you want to use a thread to create the TAPICalss?? Did you try to use the BackgroundWorker threads ?? Missing of the event is very uncertain , dont know why it occures .
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
Thanks for your answer, i create it in the thread for the reason that the instance is executed in another thread than the GUI-Thread. Probably there is a timeout or a "black hole" where the Hang-Up-Signal disappears if i open a new Window. Actually it works with the Telefony-API into the thread. But it worked also without a thread, but sometimes it makes problems :sigh: Now i need to test if this error occurs also with threading ...