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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
Y

yeah1000

@yeah1000
About
Posts
39
Topics
16
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Safe handle has been closed appears on program exit
    Y yeah1000

    Hello, i sometimes get the "Safe handle has been closed" exception when i CLOSE my application (in debug mode). When i run it from the exe and try to close the app i simple get the "program has stopped working" error. I use a com port to communicate with an external device. I hear it has something to do with a .net bug but is there anything i can do in the Form_closing event perhaps or somewhere else to stop it from showing when i close my program. How could i handle that exception? Heres the stack trace: System.ObjectDisposedException was unhandled Message="Safe handle has been closed" Source="mscorlib" ObjectName="" StackTrace: at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle) at System.Threading.EventWaitHandle.Set() at System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) InnerException: My idea was the following: (to make sure that the communication thread does not send anything else when user wants to exit) Form_Closing event { signal_comm_thread loop while(getSignal_from_comm_thread) } Comm_thread { if(signal_received) signal_Form_Closing event break; } But the program wont close at all this way :( Tried to use ManualResetEvents, public static variables for the signaling but nothing helps. Only way the program closes is if i add a "MessageBox.Show" in Form_Closing event after signaling comm_thread. How can that help? TY

    C# help debugging csharp com data-structures

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Oh but i did call it from the constructor, then started the background thread and inside that thread tried to access the controls.

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    I was finally able to fix the problem: Apparently the handle for the richtextbox did not exist when i tried to invoke it. Since i used it in a background thread, the invokerequired property returned 'false', sometimes causing it to display the illegal cross thread operation exception (suring program startup). The solution was to use the Form_load event which would signal the background thread when it was fully loaded. But its still a bit unclear how such a thing can happen. When does actually InitializeComponent return? When can i be sure that the control handles exist?

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Okay, that didn't help :( Any more ideas?

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    I am currently testing it with the 'this' keyword. But why should this approach solve the problem? What are the technicalities behind it? :)

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Soo, any ideas? :)

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Here is the stack trace, perhaps it can help clarify the problem...

    System.InvalidOperationException was unhandled
    Message="Cross-thread operation not valid: Control 'SomeClass' accessed from a thread other than the thread it was created on."
    Source="System.Windows.Forms"
    StackTrace:
    at System.Windows.Forms.Control.get_Handle()
    at System.Windows.Forms.Control.get_InternalHandle()
    at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
    at System.Windows.Forms.RichTextBox.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Control.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WmCreate(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
    at System.Windows.Forms.RichTextBox.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
    at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
    at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
    at System.Windows.Forms.Control.CreateHandle()
    at System.Windows.Forms.TextBoxBase.CreateHandle()
    at System.Windows.Forms.Control.get_Handle()
    at System.Windows.Forms.Ric

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Code is the following:

    Delegate:
    private delegate void ChangeTextDelegate(string text);

    Method:
    public static void ChangeText(string text)
    {
    if (richtextbox1.InvokeRequired)
    {
    richtextbox1.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
    }
    else
    {
    int startIndex;
    startIndex = richtextbox1.TextLength; <- Exception points here
    ...
    }
    }

    I call it like this: ChangeText("hello"); (in another thread)

    modified on Thursday, March 18, 2010 7:19 AM

    C# csharp help tutorial question

  • Illegal cross thread exception in Invoke method
    Y yeah1000

    Hello, i am using visual C# express 2008. I SOMETIMES get the illegal cross thread operation in my invoke method when i try to run my project. I check the InvokeRequired property, invoke the same method and in the 'else' condition i create atemporary variable and assign it the text of my control. But on that line, in the 'else' statement, inside the Invoking method i sometimes get the exception. What could be the cause? How to get rid of it? It does not occur often, but it is still a bug... TY

    C# csharp help tutorial question

  • SerialPort.ReadTimeout issue
    Y yeah1000

    Hello I am using serialport to send and receive some data. The problem is that when i use the serialport.Read(buffer, 0, x) method (x being the number of bytes i need to receive) it does not actually wait for the x nr of bytes to be available in the serialport buffer but reads what is available at certain time. I can use the BytesToRead property to wait for the x bytes to be available in the serialport buffer but then i have no way of detecting readTimeout(). I figured i could use a custom timer, but is it the best way (since i would need to start and stop the timer at high speed)? Any ideas are welcome. ty

    C# help question performance

  • How come another thread can update main controls without invoking them? [modified]
    Y yeah1000

    .Net framework 3.5 stancrm, i know that this is the way to go but my problem was that i was able to chagne the parameter without invoking :)

    C# help question announcement

  • How come another thread can update main controls without invoking them? [modified]
    Y yeah1000

    Hi, i have a strange problem. I can update any main thread control from a different thread without any cross thread exceptions. I can change the text of a textbox from the thread and from any button click handler in main thread. What are the possible causes of this kind of behavior? Can it somehow remember that i have used invoke on the controls? When i do the exact same thing in a new project i get the crossthread exception. An illustration of what i mean: private void button1_Click(object sender, EventArgs e) { Thread someThread = new Thread(Threadfun); someThread.Start(); } private void Threadfun() { label1.Text = "hello"; } ty

    modified on Thursday, February 25, 2010 10:50 AM

    C# help question announcement

  • Deleted controls still appear in InitializeComponents()
    Y yeah1000

    Is it even possible?

    C# question

  • Deleted controls still appear in InitializeComponents()
    Y yeah1000

    Anyone?

    C# question

  • How to update a listbox in another thread in another class
    Y yeah1000

    Hi, i need to add some items to a listbox in another thread and another class. The secont thread passes a ListBox item to the invoking function but i cannot access its listbox.items.add functionality. I can only set values to the common parameters to all Controls (i.e. text, name etc.) How could this be solved? ty

    C# tutorial question announcement

  • Deleted controls still appear in InitializeComponents()
    Y yeah1000

    That did not work... Any other ideas? :)

    C# question

  • Deleted controls still appear in InitializeComponents()
    Y yeah1000

    Hi, i have the following question. When i add a control to my form it gets some automatic code in the InitializeComponents method in Designer.cs. When i delete the control from my form the code will still be there. Is there an automatic way to remove the unused control declarations from InitializeComponents? TY

    C# question

  • Importing a win32 dll in C#
    Y yeah1000

    Hello, i need to import a win32 (unmanaged) dll in C#, can it be done and what would be the best way to do it? TY

    C# csharp question

  • FAT32 filesystem
    Y yeah1000

    Hi, i am having trouble understanding FAT32 filesystem. As i understand there is a cluster in the file allocation table for each cluster in the data area of the disk (containing its address). But that would mean that half of the size of the disk would be taken up by FAT. If all the clusters in the data area are used that means that there is an equal number of clusters in the FAT that points to each and every one of them. Could someone please explain :)

    IT & Infrastructure

  • Question about an BYTE value changing into pointer, then array
    Y yeah1000

    Hi, i am in trouble with the following: //function declarations// void function1(); void function2(BYTE *temp); //functions// void function1(){ BYTE temp; function2(&temp); } void function2(BYTE *temp){ int i; for(i=0;i<10;i++){ temp[i] = 1; } } How come temp can be used as an array in function2 ? function2 requires a pointer to BYTE value not a BYTE array... TY

    C / C++ / MFC question data-structures
  • Login

  • Don't have an account? Register

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