Link to home
Start Free TrialLog in
Avatar of YANKAUSKAS
YANKAUSKASFlag for United States of America

asked on

How to create a thread for this code?

have the code bellow, because all the code is in the Main program, the program will never fully start, the mr.response will not be printed out because the monitorCall always null if there is no call call to the channel which is monitored. I want this program still print out the mr.response when there is no call call to channel. I know we have to use thread, could you suggest me how to use thread in this code? Thank you very much!

static void Main(string[] args)
        {
	// Initialization here...           
            try
            {
                // Connect to Remote server ...
            }
            catch (Exception ex)
            {
            }
 
            Console.WriteLine("Monitor the phone.");
            // Wait for Link event
            LinkEventHandler le = new LinkEventHandler(dam_Link);
            manager.Link += le;
            while (monitorCall == null)
            {
                System.Threading.Thread.Sleep(100);
            }
            manager.Link -= le;
            // Now send Monitor action
            MonitorAction ma = new MonitorAction();
             try
            {
                ManagerResponse mr = manager.Connection.SendAction(ma, 10000);
                Console.WriteLine("Monitor Call" + "\n\tResponse:" + mr.Response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial