473,585 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting a System.InvalidO perationExcepti on was unhandled (no specific location given)

9 New Member
Hey everyone... Firstly let me tell you this is a project that is probably alittle over my head... I have played with programming most of my life, but I have only been doing VB 2005 for about 2 weeks. I know the concepts of most issues, but multi-threading seems to be giving me a headache... anyways here is what is happening...

I have use the MSDN code sample to create a Async TCP server (using sockets, and beginaccept, etc, not Tcplistener or TcpClient), and converted it some to work in a windows form. I got that working, sending all information to a Msgbox as it is transfered from the Console application for the client, no bugs were in this part of the code as far as I know. But on attempting to change Textbox1 in Form1, I realized that I couldn't (it was in the original thread, whereas the message was in the async tcp thread). I have spent a few days trying to learn to use the invoke statement. Seems it is working, as the textbox does get changed to reflect my stream that I recieve from the client. BUT and there is always a BUT I guess, I now get this error at the last End Sub of my async server code.

Getting System.InvalidO perationExcepti on was unhandled

The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone ).

this is the code I added to the server code to invoke the textbox1 in form1.

Expand|Select|Wrap|Line Numbers
  1. Public Class AsynchronousSocketListener
  2.     ' Thread signal.
  3.     Public Shared allDone As New ManualResetEvent(False)
  4.     Delegate Sub UpdateTextBox(ByVal message As String)
  5.  
  6.     Private Shared Sub Handler1(ByVal strInMessage As String)
  7.         Dim f As Form1 = My.Application.OpenForms("Form1")
  8.         f.Invoke(New UpdateTextBox( _
  9.            AddressOf f.UpdateMessage), New Object() {strInMessage})
  10.     End Sub
  11.  
and the code from the Form1.vb

Expand|Select|Wrap|Line Numbers
  1.    Public Sub UpdateMessage(ByVal strInMessage As String)
  2.         Me.TextBox1.Text = strInMessage & vbCrLf & Me.TextBox1.Text
  3.     End Sub
  4.  
at then end of my async class:

Expand|Select|Wrap|Line Numbers
  1.     Private Shared Sub SendCallback(ByVal ar As IAsyncResult)
  2.         ' Retrieve the socket from the state object.
  3.         Dim handler As Socket = CType(ar.AsyncState, Socket)
  4.  
  5.         ' Complete sending the data to the remote device.
  6.         Dim bytesSent As Integer = handler.EndSend(ar)
  7.        Handler1("Sent " & bytesSent & " bytes to client." & vbCrLf & Form1.TextBox1.Text)
  8.  
  9.         handler.Shutdown(SocketShutdown.Both)
  10.         handler.Close()
  11.         ' Signal the main thread to continue.
  12.         allDone.Set()
  13.         'Form1.TextBox1.Text = "Sent " & bytesSent & " bytes to client." & vbCrLf & Form1.TextBox1.Text
  14.  
  15.     End Sub 'SendCallback
  16.  
when I comment out

Expand|Select|Wrap|Line Numbers
  1.         Handler1("Sent " & bytesSent & " bytes to client." & vbCrLf & Form1.TextBox1.Text)
I will no longer get the error, but the textbox (of course) does not update. And as I mentioned, the textbox does get updated right before I see the error message pup up, with a break in my code the error message shows at the End Sub 'SendCallback

To some this code may look femiliar as I used an example that was posted on these forms.

Thanks in advance, and if you need more information feel free to ask, this is just a pet project for me, but something I would really like to fix, my whole project seems to depend on it.
Sep 7 '07 #1
1 2638
Tenowg
9 New Member
Sorry for the friendly bump, but I am now at the point where I need to figure this out, or I can't go any farther in my project...

thanks, and sorry again.
Sep 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1967
by: Hari Koduru | last post by:
Hi All, I am getting the following exception in an ASP.NET application. Exception Details: System.InvalidOperationException: Application is restarting. I have been to the following Support page
6
6092
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 I received an error message: "The ConnectionString property has not been initialized.
1
6192
by: Trygve Lorentzen | last post by:
Hi, my webservice is running on Win2000 SP4, IIS 5.0 fully patched, connecting to a MySQL database and mainly returning Typed DataSet's from webmethods. After running for a while, generally a few days, the webservice stops responding and the .NET windows app client fails with no informative error message. When I try to run any webmethod...
0
2398
by: nirupama | last post by:
Sir, I am new to the Nunit,nunitasp i am gettin an error as "System.InvalidOperationException:the specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type" i have used nunit.framework,nunitasp as references ,but when i am using txt1.tex="asdf", then i am getting can u plz send the...
0
1892
by: banduraj | last post by:
I get an System.InvalidOperationException when trying to Serialize a struct that has a type refrenced from another library. The exception is: System.InvalidOperationException was unhandled Message="Unable to generate a temporary class (result=1).\r\nerror CS0012: The type 'SecureSpeak.Protocol.ssContactItem' is defined in an assembly that...
2
3032
by: Craig | last post by:
I have the need to write a byte of information to a specific location in a text file. eg. the file looks something like this. FYYNN Line 1 Line 2 <eof>
3
14196
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to transfer file attachments to and from the server. I'm using WSE 2.0 SP3 which is supposed to support FX 2.0, as far as I know. (We will soon move on...
0
1248
by: John H | last post by:
Hi, Strange error with serialisaation on .net 1.1 Sp1 when a the assembly containing the type is in the Gac as well as on e.g c:\customdlls. ObjValue in below code is populated with and array of classes which are defined in an assembly loaded from c:\customdlls using loadfrom. This same assembly is also in the gac. The below code snippet...
1
7171
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread. Logic is: 1) i will first create a thread to display a splash screen until a big process is completed 2)then i will close the splash screen and kill the thread.
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.