Dart Home | PowerTCP Telnet for .NET | Custom Development | Reply | PowerTCP Telnet for .NET Topics | Forums |
Author | Forum: PowerTCP Telnet for .NET Topic: Proper procedure to wait at main thread |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted March 12, 2010 5:58 PM Hi Everyone, What is the proper way to wait at main thread when using telnet1.Start(automateSession, null)? I want to continue executing more code upon completion of telnet1.Start(automateSession, null). Sample code: private void button1_Click(object sender, EventArgs e) { //Event handlers were added in the designer //Start the process on a worker thread (no state info passed in) telnet1.Start(automateSession, null); } private void automateSession(Telnet telnet, object notUsed) { //This function executes on a worker thread, providing multi-threaded, asynchronous operation try { //Connect telnet.Connect("myServer"); //Login to the server, marshal data to the UI thread telnet.Marshal(telnet.Login("myUsername", "myPassword", "$"), null); //Send a list command telnet.Write("ls -la\r"); //Wait for prompt, marshal data to the UI thread telnet.Marshal(telnet.Read("$"), null); //Send an exit command; server will close the connection telnet.Write("exit\r"); //Read any remaining data before the shutdown telnet.Marshal(telnet.ReadToEnd(), null); } catch (Exception ex) { //Report errors to the UI thread telnet.Marshal(ex); } } void telnet1_Data(object sender, DataEventArgs e) { //Add data received to the textbox textBox1.AppendText(e.Data.ToString()); } void telnet1_Error(object sender, System.IO.ErrorEventArgs e) { //Add error messages to the textbox textBox1.AppendText(e.GetException().Message); } void telnet1_StateChanged(object sender, EventArgs e) { //Change appearance of textbox when connected textBox1.BackColor = (telnet1.State == ConnectionState.Closed) ? SystemColors.ControlDark : SystemColors.ControlLight; } Thanks very much, xplorer2k |
Jamie Powell (Admin) From: Rome, NY USA Posts: 448 Member Since: 03/13/07 Extra Support Options Custom Application Development |
posted March 15, 2010 4:34 PM You can call automateSession as a blocking call, instead of with telnet1.Start (which calls a method asynchronously). This should provide a solution for what you have described. ------ |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted March 15, 2010 7:27 PM Thanks Jamie, However, I need to make this call asynchronously, as I will need to run 10 or 20 threads in parallel (asynchronously), then wait at main thread upon completion of each/all these threads. I don't want to do this synchronously as it will take longer. Thanks again, xplorer2k |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted March 18, 2010 6:22 PM Thanks Jamie, I need to make calls asynchronously, as I will need to run 10 or 20 threads in parallel (asynchronously), then wait at main thread upon completion of each/all these threads. Thanks again, xplorer2k |
Reply | PowerTCP Telnet for .NET Topics | Forums |
This site is powered by PowerTCP WebServer for ActiveX |