Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Call function from thread

Call function from thread

Scheduled Pinned Locked Moved C#
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    baerten
    wrote on last edited by
    #1

    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 :)

    V 1 Reply Last reply
    0
    • B baerten

      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 :)

      V Offline
      V Offline
      vikas amin
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • V vikas amin

        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

        B Offline
        B Offline
        baerten
        wrote on last edited by
        #3

        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 ...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups