| Dart Home | PowerTCP Sockets for .NET | Custom Development | Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
| Author | Forum: PowerTCP Sockets for .NET (Secure and Standard) Topic: Unhandled exception in user's Event Handler |
| skcr_plus suhail_kaleem@hotmail.com From: isl, AB USA Posts: 16 Member Since: 07/06/03 |
posted July 6, 2003 7:59 AM Ok ! I have tree view control on my form , now i can add the nodes to it if out side the event( Handles Server1.Connection) but when i call the fucntion to add nodes when inside the event i get a error which is : Unhandled exception in user's Event Handler Argument prompt cannot be converted to type string This is the fucntion i call when inside the event Function addtree(ByVal treenode1) Me.TreeView2.Nodes.AddRange(New System.Windows.Forms.TreeNode() {treenode1}) ' MsgBox(treenode1) End Function But out side the event it works fine any help ? |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted July 8, 2003 9:25 AM Hi, You must use delegates to marshall the data from the worker thread handling the connection, to the User Interface thread where the TreeView resides. Below I have a simple example. In future releases of the Tool, the samples will be updated to demonstrate this. -ken Delegate Sub UiDelegate(ByVal text As String) Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.Nodes.Add("Clients") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Server1.Listen(777) End Sub Private Sub Server1_Connection(ByVal sender As Object, ByVal e As Dart.PowerTCP.Sockets.ConnectionEventArgs) Handles Server1.Connection BeginInvoke(New UiDelegate(AddressOf AddNode), StringToObjectArray(e.Tcp.RemoteEndPoint.Address.ToString())) End Sub Private Sub AddNode(ByVal s As String) TreeView1.Nodes(0).Nodes.Add(s) End Sub Private Function StringToObjectArray(ByVal s As String) As Object() Dim o(0) As Object o(0) = s Return o End Function |
| skcr_plus suhail_kaleem@hotmail.com From: isl, AB USA Posts: 16 Member Since: 07/06/03 |
posted July 8, 2003 11:42 AM Yes it worked It Means it must use all my events not by tcp component event on spearte thread?? Thanks for the help Suhail kaleem |
| cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted July 9, 2003 2:26 AM Really? Is this only for Servers that use Listen? I ask, because I have a c# class that owns a tcp object that does a lot of sending and receiving. In my EndReceive() function, I update many UI elements that were passed into the class by reference. It works fine. Should it not be working, then? Christopher |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted July 9, 2003 9:44 AM Hi, With the Server component, delegates must be used. For non-server components, there is a SynchronizingObject property that can be set for asynch operations. This can be necessary because EndXXX events are firing on non-UI threads. Some UI operations will work fine, while others will not. In the simple example below, the Clear call will work whether or not the SynchronizingObject is set. However, the Focus call will only work if the property is set. -ken Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click TextBox1.Text = "Hello" 'Tcp1.SynchronizingObject = Me 'uncomment to allow Focus Tcp1.BeginConnect("myEchoServer", 7) End Sub Private Sub Tcp1_EndConnect(ByVal sender As Object, ByVal e As ExceptionEventArgs) Handles Tcp1.EndConnect TextBox1.Clear() TextBox1.Focus() End Sub |
| dheerajjuneja dheeraj@tometasoftware.com From: Spokane, WA USA Posts: 1 Member Since: 06/06/04 |
posted June 6, 2004 2:53 PM Ken, I am facing a similar situation, wherein i was using the normal sockets (PowerTCP Sockets) and i have to switch over to SSL Sockets. I changed the references everywhere where required, but couldn't find how to set the property "SynchronizingObject" as it seems that SSL Sockets lack this property. But as a result i am getting the form freeze, there is a form which is updating other forms in the EndRecieve method, earlier it worked but it has stopped now (still some areas are functional, and others not). Please advise how to proceed. Regards, Dheeraj Juneja |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted June 7, 2004 11:55 AM Hi, The components of the SSLSockets Tool have SynchronizingObject properties, just like their non-secure counterparts. If yours do not, make sure to install the latest Tool from our website. There is no guide for converting an app, but our samples are written for both Tools, so you may want to examine the samples to see what code was added for the secure versions. The code contained within the #if SECURE ... #end if is the code that has been added specifically for the secure samples. -ken |
| Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|