none
app hang RRS feed

  • Question

  • I have 50+ pc's with 24/7 VS2010 app on them. I have XP, Win7, Win8...On some of them, from time to time I get app hang. In windows error log I get cross-thread. Analyzing DMP in vs2013 I got following stack.

                  

    ntdll.dll!_ZwWaitForSingleObject@12()
    ntdll.dll!_ZwWaitForSingleObject@12()
    clr.dll!CLREventWaitHelper2()
    clr.dll!CLREventWaitHelper()
    clr.dll!CLREventBase::WaitEx(unsigned long,enum WaitMode,struct PendingSync *)
    > clr.dll!WKS::WaitForFinalizerEvent(class CLREventStatic *)
    clr.dll!WKS::GCHeap::FinalizerThreadWorker(void *)
    clr.dll!ManagedThreadBase_DispatchInner()
    clr.dll!ManagedThreadBase_DispatchMiddle()
    clr.dll!ManagedThreadBase_DispatchOuter()
    clr.dll!WKS::GCHeap::FinalizerThreadStart(void *)
    clr.dll!Thread::intermediateThreadProc(void *)
    kernel32.dll!@BaseThreadInitThunk@12()
    ntdll.dll!___RtlUserThreadStart@8()
    ntdll.dll!__RtlUserThreadStart@8()

    I guess GC is making problems, so I removed it. Can somebody helps me understand what is going on?

    thx

    Thursday, May 21, 2015 4:59 AM

All replies

  • Hello mrcic.zeljko
    To further help you about this issue, I am trying to invoke someone experienced to help look into this thread, this may take some time and as soon as we get any result, we will post back.

    Regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 22, 2015 5:51 AM
  • thanks Kristin

    Friday, May 22, 2015 10:06 AM
  • Looks like a possible issue in one of your finalizers. Are you using any unmanaged code like COM, or a COM Server, or PInvoke? If this already rings a bell try wrapping the finalizer (or the ones that might be suspicious) in a try/catch block and logging inside the catch as a finalizer should never throw an exception.

    Searching on WaitForFinalizerEvent (point in stack above your bolded line item) I found the following article which demonstrates how to get object information in the call stack at that point by unwinding the stack. I did not write it so if you have specific questions on it maybe someone else will respond as its a little over my head.

    http://blogs.msdn.com/b/ntdebugging/archive/2010/05/12/x64-manual-stack-reconstruction-and-stack-walking.aspx

    I hope this helps.


    Mark as answer or vote as helpful if you find it useful | Igor

    Friday, May 22, 2015 10:50 AM
  • I have to admit that I do not understand dump files...just starting to learn...never needed that so far.

    A little clue...I have few dock-able windows that separate, each on own thread, writes data to GUI thread. So i have decided to make those windows created from the main thread to avoid invokerequired when writing data. I also had invokerequired afther that although all controls are created on same thread! I investigated further to find out that timer(System.Timers.Timer, not winfors, not thread timer), on which thick event I'm writing data is causing invokerequired. codeproject: It invokes the available thread in ThreadPool to run the interface, what ever that means...and if there are no available threads?

    Found some articles and started to use winforms timer that had to be started by delegate in order to fire.

    no invokerequired calls so far..


    Friday, May 22, 2015 7:43 PM
  • Your posted callstack is not in a Finalizer method. It's the Finalizer thread in a quiescent state, waiting to be woken up by WaitForPendingFinalizers. The Finalizer thread always exists, but spends most of it's time waiting to be woken up in WaitForFinalizerEvent.

    An active Finalizer thread processing Finalizers would have a FinalizeAllObjects call on it:

    0:002> kc
     #
    00 KERNELBASE!DebugBreak
    01 clr!DebugDebugger::Break
    02 mscorlib_ni!System.Diagnostics.Debugger.Break()
    03 ConsoleApplication9!ConsoleApplication9.Test.Finalize() <<< finalizer
    04 clr!FastCallFinalize
    05 clr!MethodTable::CallFinalizer
    06 clr!WKS::CallFinalizer
    07 clr!WKS::DoOneFinalization
    08 clr!WKS::FinalizeAllObjects    <<<<<<<<<<<<<<<<<<<<<<<<<<
    09 clr!WKS::GCHeap::FinalizerThreadWorker
    0a clr!ManagedThreadBase_DispatchInner
    0b clr!ManagedThreadBase_DispatchMiddle
    0c clr!ManagedThreadBase_DispatchOuter
    0d clr!ManagedThreadBase_NoADTransition
    0e clr!ManagedThreadBase::FinalizerBase
    0f clr!WKS::GCHeap::FinalizerThreadStart
    10 clr!Thread::intermediateThreadProc
    11 KERNEL32!BaseThreadInitThunk
    12 ntdll!__RtlUserThreadStart
    13 ntdll!_RtlUserThreadStart

    In other words, the hang is due to another thread or threads.

    What is the active thread doing? The active thread will have a '.' in the first column when you run the native threads command '~'

    0:002> ~
       0  Id: 3ec4.2564 Suspend: 1 Teb: 7eeae000 Unfrozen
       1  Id: 3ec4.2300 Suspend: 1 Teb: 7eeab000 Unfrozen
    .  2  Id: 3ec4.1380 Suspend: 1 Teb: 7eea8000 Unfrozen

    Wednesday, June 3, 2015 12:48 AM
  • it is 0 thread !runaway

    0:1064 0 days 0:02:52.843

    8:c20 0 days 0:00:00.968

    12:e24 0 days 0:00:00.796

    so I guess it is 0

    ~ k

    ChildEBP RetAddr  
    0093e534 6f77acec user32!NtUserShowWindow+0xc

    0093e570 6f724748 System_Windows_Forms_ni+0x1facec

    0093e618 6f72ea73 System_Windows_Forms_ni+0x1a4748

    0093e640 6f7384a4 System_Windows_Forms_ni+0x1aea73

    0093e648 6f7353d3 System_Windows_Forms_ni+0x1b84a4

    0093e694 6f735202 System_Windows_Forms_ni+0x1b53d3

    0093e6c0 6fcaebb3 System_Windows_Forms_ni+0x1b5202

    0093e6d8 6fcd2b54 System_Windows_Forms_ni+0x72ebb3

    0093e778 6fcd2827 System_Windows_Forms_ni+0x752b54

    0093f024 6fcb4071 System_Windows_Forms_ni+0x752827

    0093f03c 6fcb459c System_Windows_Forms_ni+0x734071

    0093f06c 7001c945 System_Windows_Forms_ni+0x73459c

    0093f0b8 6f735ad5 System_Windows_Forms_ni+0xa9c945

    0093f140 6f735389 System_Windows_Forms_ni+0x1b5ad5

    0093f194 6f735202 System_Windows_Forms_ni+0x1b5389

    0093f1c0 6fcae158 System_Windows_Forms_ni+0x1b5202

    0093f1d0 73347447 System_Windows_Forms_ni+0x72e158

    0093f1f4 73348102 Microsoft_VisualBasic_ni+0x127447

    0093f21c 73346f61 Microsoft_VisualBasic_ni+0x128102

    0093f298 72292552 Microsoft_VisualBasic_ni+0x126f61

    0093f2a4 7229f237 clr!CallDescrWorkerInternal+0x34

    0093f2f8 7229ff60 clr!CallDescrWorkerWithHandler+0x6b

    0093f378 723b671c clr!MethodDescCallSite::CallTargetWorker+0x152

    0093f49c 723b6840 clr!RunMain+0x1aa

    0093f710 723f3dc5 clr!Assembly::ExecuteMainMethod+0x124

    0093fc10 723f3e68 clr!SystemDomain::ExecuteMainMethod+0x63c

    0093fc68 723f3f7a clr!ExecuteEXE+0x4c

    0093fca8 723f6b86 clr!_CorExeMainInternal+0xdc

    0093fce4 73a8ffcc clr!_CorExeMain+0x4d

    0093fd20 73c3bbcc mscoreei!_CorExeMain+0x10a

    0093fd30 76c5919f mscoree!_CorExeMain_Exported+0x8c

    0093fd3c 76fda8cb kernel32!BaseThreadInitThunk+0xe

    0093fd80 76fda8a1 ntdll_76f90000!__RtlUserThreadStart+0x20

    0093fd90 00000000 ntdll_76f90000!_RtlUserThreadStart+0x1b

    Thursday, June 4, 2015 2:02 PM
  • I have changed my threading approach...

    so there is no way(I think) of getting cross thread app hang...

    now I have situation that app hangs for 5 secs and then resume?!

    small dump is located here. Any help will be great!!!

    Thursday, June 4, 2015 2:17 PM
  • going crazy here...any help will be appreciated.

    Looking over windows log, I found two errors, side by side. First is this one:

    Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidOperationException Stack: at System.Drawing.Image.SelectActiveFrame(System.Drawing.Imaging.FrameDimension, Int32) at System.Drawing.ImageAnimator+ImageInfo.UpdateFrame() at System.Drawing.ImageAnimator.UpdateFrames() at Oktan.frmNaplata.OnFrameChanged(System.Object, System.EventArgs) at System.Drawing.ImageAnimator+ImageInfo.OnFrameChanged(System.EventArgs) at System.Drawing.ImageAnimator+ImageInfo.set_Frame(Int32) at System.Drawing.ImageAnimator.AnimateImages50ms() at System.Threading.ThreadHelper.ThreadStart_Context(System.Object) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ThreadHelper.ThreadStart() 

    and right after that my app error, windows shut it down.

    Usually I just get app hang, cross thread error in log.

    I have small animated gif, indicating to users that they are using special app mod for automatic printing. Could this two be related? Is my cross thread error in fact caused by problems in drawing? I can see that thread in VS2013 debugging small dmp, but I don't know much about dmp analyze to make conclusion. Google is poor about this.



    Sunday, June 7, 2015 4:50 AM
  • "Is my cross thread error in fact caused by problems in drawing?"

    Maybe yes, maybe not. In case you don't know ImageAnimator calls OnFrameChanged on a background thread so whatever you do in OnFrameChanged needs to take that into account.

    But the cross thread error appears to be in a threadpool thread (3980) so it may be unrelated. When the application was stopped that thread was in a GetWindowTextLengthW call, maybe triggered by your code accessing the Text property of a control. Interestingly, at that point the main thread (which is probably the thread that should process the message sent by GetWindowTextLength) is waiting for a GC to complete and so are other threads, including the System.Drawing thread that's supposed to call OnFrameChanged.

    I'd try fixing the cross thread error and see how it goes.

    Sunday, June 7, 2015 5:58 AM
    Moderator
  • Problem is that exception is random and I can not reproduce it in development environment.

    I'm using threads, but in safe manner, begininvoke etc...

    GetWindowTextLengthW  is called when? When I put some text in textbox, select text or something else.

    Second, I have pc's that are on for 4-5 days without a crash!? It can be due to framework, maybe drivers...

    like in your reply...to many "maybe"...

    I have removed gif...9 hours, no hangs so far...that animated gif gave me problems in past, showing red cross of doom from time to time on some pc's...I'm better of. I have also noticed that there is some 3rd party app that steals focus from mine. Maybe it got something with hanging? 

    Thanks Mike, if you could just elaborate on GetWindowTextLengthW ?

    Sunday, June 7, 2015 6:44 AM
  • "GetWindowTextLengthW  is called when? When I put some text in textbox, select text or something else."

    Usually it is called when you get the Text property of a WinForms control but there are other places that result in GetWindowTextLength function being called, for example TextBox.AppendText and TextBox.get_SelectedText. Can't tell exactly what's going on here because the call stack contains System.Windows.Forms.ni.dll and I don't have symbols for it.

    "have removed gif...9 hours, no hangs so far...that animated gif gave me problems in past, showing red cross of doom from time to time on some pc's...I'm better of."

    Could be, System.Drawing is not very reliable. I does have a habit of blowing up unexpectedly and in weird ways, especially when images are involved. It may also be a problem in your code - failure to dispose System.Drawing objects or disposing them while they are still in use, using System.Drawing objects from multiple threads in an unsupported way.

    "I have also noticed that there is some 3rd party app that steals focus from mine. Maybe it got something with hanging?"

    Unlikely.

    Sunday, June 7, 2015 7:06 AM
    Moderator
  • Mike, what do I need to see what is System.Windows.Forms.ni.dll referring to? pdb file? I'm not so good in windbg.

    On the other hand I do not have calls to any textbox. I just have one on mainform and referencing  it not so often or not at all. Are you sure that is where problem occurs.

    thanks once again. I'm so desperate, I can not find any exception or something solid to move on.

    Sunday, June 7, 2015 6:51 PM
  • I'm not sure if you can do much about Windows.Forms.ni.dll with the memory dump you have. As far as I can tell it doesn't have enough information in it to enable managed debugging, only native debugging works. And native debugging doesn't understand ni.dll files...

    Anyway, try generating a .pdb file for that dll. Execute the following command at a command prompt:

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe createpdb c:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\2781e84862746a34f026d0ee179eed2b\System.Windows.
    Forms.ni.dll C:\SomeSymbolsDir

    SomeSymbolsDir can be any directory you want as long as the debugger is configured is configured to search symbols in it.

    I can't test on my machine cause I have a different System.Windows.Forms.ni.dll.

    That said, maybe you should simply get rid of that animated gif and perhaps the problem will go away.

    Sunday, June 7, 2015 7:12 PM
    Moderator
  • I can not find c:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\...

    can I use pdb from VS project?

    removed animated gif...ok so far...but I don't think that is solution. 

    How can I catch that error? Is there a way? I have 

    AddHandler Application.ThreadException, AddressOf Form1_UIThreadException

    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException

    Dim f As New frmMain

    f.ShowDialog()

    in my sub main()

    but nothing came up.

    On the other hand, I have pc's that are on for days with no hang...crazy!
    Monday, June 8, 2015 6:45 AM
  • "I can not find c:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\..."

    That likely means that the WinForms dll on your machine is different from the one on the machine the memory dump was obtained from.

    "How can I catch that error? Is there a way?"

    Which error? Right now you seem to have 3 different problems and it's not clear if and how they're connected:

    • an exception thrown by ImageAnimator.UpdateFrames. You can add a try/catch in that code. But that exception should not appear in the first place and attempting to swallow that exception might move the problem somewhere else.
    • a "cross thread error in log". How does that error look anyway? Last time I checked WinForms doesn't usually throw such errors unless the application is run in the debugger.
    • application hang - obviously attempting to catch exceptions won't help you with that part

    "On the other hand, I have pc's that are on for days with no hang...crazy!"

    Anything different between those PCs? OS version, updates, .NET version etc.

    Monday, June 8, 2015 7:30 AM
    Moderator
  • thanks for wasting your time on me...

    removed gifs so there is problem...

    • a "cross thread error in log". How does that error look anyway? Last time I checked WinForms doesn't usually throw such errors unless the application is run in the debugger.

    "application is run in the debugger"?

    windows app error log event:

    The program xxx.exe version 1.0.0.0 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Action Center control panel.
     Process ID: 1690
     Start Time: 01d0a161ec8315dd
     Termination Time: 16
     Application Path: C:\xxx.exe
     Report Id: e23697ba-0d58-11e5-86d0-3085a9eb8363

    Binary data:


    In Words

    0000: 00720043 0073006F 002D0073 00680074 
    0008: 00650072 00640061 00000000  


    In Bytes

    0000: 43 00 72 00 6F 00 73 00   C.r.o.s.
    0008: 73 00 2D 00 74 00 68 00   s.-.t.h.
    0010: 72 00 65 00 61 00 64 00   r.e.a.d.
    0018: 00 00 00 00               ....


    as for pc's tried framework, made it same...pc's with hangs do have some apps that make my app lost focus, anything else is not relevant, I think.

    App is run in debugger?
    Monday, June 8, 2015 7:50 AM
  • ""application is run in the debugger"?"

    Yes, if you attempt to access a WinForms control from another thread usually you don't get any exception when the application is run outside the debugger. But in debugger you get an InvalidOperationException in such cases.

    "windows app error log event"

    Interesting, Windows Error Reporting somehow guessed that the hang is caused by cross thread access. Obviously, that's not an exception you can catch, it's just the result of the analysis performed by Windows Error Reporting and it may or may not be the actual cause of the hang.

    I'm not sure what else can be done with the available information. For all I know it could be some kind of memory corruption caused by System.Drawing which prevents the GC from making progress. The main thread gets stuck waiting for GC and the threadpool thread which does the cross thread operation gets stuck as well waiting for the main thread. And the System.Drawing animation thread is also stuck waiting for GC. Pure speculation...

    Monday, June 8, 2015 9:37 AM
    Moderator
  • yeah...

    not sure where to look...

    I have two dmp files, here and here. No clue what to do with them. Opened in VS2013, thats all.

    Since removing gifs, it is better, no hangs. I have noticed that app hangs for few seconds(10 to 20) and then resume, and for simple tasks, like opening menu(no db connection, no complex operation). Bigger dmp is created at that moment. 


    Tuesday, June 9, 2015 3:29 AM
  • Are those 2 dmp files also the result of a hang?

    One of them looks perfectly fine, I don't see any indication of a hang or any other problem.

    The other one is a bit more interesting, the main thread is in a NtUserSetFocus call that's the result of displaying a MessageBox from a method named lblSmena_Click. If this dump is the result of a hang then it would mean that NtUserSetFocus hanged which is a bit odd.

    Tuesday, June 9, 2015 4:52 AM
    Moderator
  • How can see that label code? windbg?

    I just don't wont to bother any more...

    that is that hang for 5,10,15 sec. if user does wait it came up ok...but when user thinks that app is not responsive and will not be, hi try to close app...and I get hang.

    Why is there NtUserSetFocus when I display msgbox? Can set focus on txt box produce hang? Can I try all over again and study to be a lawyer?

    Tuesday, June 9, 2015 6:35 AM
  • "How can see that label code? windbg?"

    Neah, no need to go that far, I just loaded the memory dump in VS (not sure if VS2010 has this feature but I have VS2013).

    "that is that hang for 5,10,15 sec. if user does wait it came up ok...but when user thinks that app is not responsive and will not be, hi try to close app...and I get hang."

    I see. Well, the odd thing is that one of the dumps from your last post doesn't show any signs of a hang. And the other is the set focus thing which doesn't normally hang.

    "Why is there NtUserSetFocus when I display msgbox?"

    Because the message box is activated when it is displayed and one of its buttons gets the focus.

    "Can set focus on txt box produce hang?"

    I think it's possible to get into some trouble if you're trying to perform validation in the LostFocus/GotFocus events and the validation code displays message boxes. Since the displaying a message box changes the focus it's possible to end up in a cycle but that shouldn't cause a hang. If anything, that will lead to a StackOverflowException.

    "Can I try all over again and study to be a lawyer?"

    I'm not sure what you mean by that.

    Tuesday, June 9, 2015 6:55 AM
    Moderator
  • A just tried myself....

    click on label, menu item....app hangs...

    if I wait app resume, no problem.

    If I try to stop it, close it, I get cross-thread error.

    It looks like app is somehow unresponsive. although it response on hovering events.(I see color of controls changing while moving mouse toward label or menu). So that is problem...but solution?

    what to look next?

    Tuesday, June 9, 2015 7:37 AM
  • "click on label, menu item....app hangs..."

    Maybe it's simply something you do on the main thread and it takes a long time. Database access, network access etc.

    "what to look next?"

    If you can reproduce this on your machine try running the application in the VS debugger and when it hangs break into the debugger and see what the application is doing.

    Tuesday, June 9, 2015 8:49 AM
    Moderator
  • I wish I can reproduce it.

    New dump is here. If it is not to late, there are some screenshots of my app here. Go to page 17. Window on the left side(with pumps) is invoking delegate to write new data to main form table, underlying grid.

    I have timer on main form, that does two tings: setting current time and updating some data in status strip. No db calls...

    that is the only thing working all the time. Other actions, deleting, adding rows is performed on main thread.

    this is my delegate call

        Dim result As IAsyncResult = oCtrl_DR.dgvArtikli.BeginInvoke(New Func(Of UInteger)(Function() oCtrl_DR.AddToDataTable(DR)))
             Threading.Thread.Sleep(0)                            
    
            Dim threadId As Integer    
    Dim returnValue As Integer = oCtrl_DR.dgvArtikli.EndInvoke(result)

    where oCtrl_DR = oTab_page.Controls(0) , user ctrl.

    Public Function AddToDataTable(ByVal dr As DataRow) As Integer
            
            dr("TransID") = 0
          
            Try
                tblKasa.Rows.Add(dr)
            Catch ex As Exception
                Return 1
            End Try
      dr = Nothing
            Return 0
        End Function
    Maybe I'm doing something wrong?


    Tuesday, June 9, 2015 3:44 PM
  • "Window on the left side(with pumps) is invoking delegate to write new data to main form table, underlying grid."

    I think I'm missing something. Why do you need to use BeginInvoke there?

    Tuesday, June 9, 2015 9:35 PM
    Moderator
  • and EndInvoke...

    because users can perform action on GUI thread, that blocks it, so I need EndInvoke on background thread.

    I was just going over my settings in explorer window, my app was active in background. I closed explorer window, giving focus to my app and it hangs?!!!!!

    no action, no clicks...hang?

    Wednesday, June 10, 2015 4:36 AM
  • But where does that background thread come from? If you click something the event handler will be executed in the main thread, not in a background thread.
    Wednesday, June 10, 2015 5:06 AM
    Moderator
  • control on the right starts on it's thread...and write it to table on control on tabctrl on main form(thread)

    I started to analyze differences between two pc's...copy dir from working one to not working one...I think I'll come up with solution, but it is early to say...stay tuned please.

    Main problem is that windbg and error reporting is so misguided....but we'll see.
    Wednesday, June 10, 2015 6:07 AM
  • "control on the right starts on it's thread...and write it to table on control on tabctrl on main form(thread)"

    But that control appears to be itself in the main form. It can be on its on different thread. In general, the all the UI should use a single thread, doing otherwise is asking for trouble.

    Wednesday, June 10, 2015 6:54 AM
    Moderator
  • just copied my app folder from 4+ days working pc to one that had hangs....after few hours hanged again. Restarted app and went to win log. On closing it, my app was in background and should get focus. It hanged again at that moment.

    Didn't even work with it!!!!

    both pc's has Win7 sp1, integrated graphic card. Framework is 4 v. client and v. extended.

    I'm 99% sure that it got something to do with pc.

    There is something I should check or uncheck, and problem will go away.

    Thursday, June 11, 2015 11:17 AM
  • "There is something I should check or uncheck, and problem will go away."

    Probably not. Since other apps probably work on that PC it's like that is your app that has a problem.

    You haven't clarified what's going on with that control on the right that starts on its thread...

    Thursday, June 11, 2015 1:55 PM
    Moderator
  • control on left is doing some readings inserting data to the table(grid) on the right using begin/end invoke.

    yeah, I also think it is my app, but can not explain not hanging on some places...


    Thursday, June 11, 2015 3:09 PM
  • "control on left is doing some readings inserting data to the table(grid) on the right using begin/end invoke."

    Yes, you told me that before. What I don't get is why Begin/EndInvoke is needed there. There should be a single thread that does all that stuff. If have more than one thread then it's likely that you're doing something wrong.

    Thursday, June 11, 2015 3:14 PM
    Moderator
  • because clients can delete, edit rows in grid...

    control on left is somehow independent, doing it's own stuff...on the right there is tab control. users can do many actions on tab with grid or some other....

    if there is some cross thread issue, why not hang after few minutes?

    why wait for few hours?...there were 10+ hours without hang.

    just removed Control.CheckForIllegalCrossThreadCalls = False and app is working OK...

    haw can this be cross thread issue?



    Thursday, June 11, 2015 3:25 PM
  • "haw can this be cross thread issue?"

    Well, I don't know because nothing in your post explains the need for those BeginInvoke calls.

    Thursday, June 11, 2015 4:12 PM
    Moderator
  • control on the left is adding row...GUI is busy, printing...so begin/end invoke...

    maybe I should get something like "Cross-thread operation not valid: xxxx accessed from a thread other than the thread it was created on"

    but nothing...and that error is handled...if I put dim x as new frmMain inside try catch I should get not handeled error exception in msg box. Why I just get hang and win error log event? 
    Thursday, June 11, 2015 4:16 PM
  • When you say "control on the left" I understand a piece of code that the control contains and as such it normally runs in the main thread. Since it runs in the main thread there is no reason to call BeginInvoke to add a row to a data grid control that's also running in the main thread. So, how does a background thread come into this picture?
    Thursday, June 11, 2015 4:29 PM
    Moderator
  • no bg thread...two forms...two controls...each doing it's own work...one accessing each other..using delegates

    what about:

    maybe I should get something like "Cross-thread operation not valid: xxxx accessed from a thread other than the thread it was created on"

    but nothing...and that error is handled...if I put dim x as new frmMain inside try catch I should get not handeled error exception in msg box. Why I just get hang and win error log event? 


    Thursday, June 11, 2015 4:42 PM
  • "no bg thread...two forms...two controls...each doing it's own work...one accessing each other..using delegates"

    Those 2 forms/control should belong to the same thread. If you somehow created controls in different threads, well, you're asking for trouble. Don't do that.

    Thursday, June 11, 2015 5:26 PM
    Moderator
  • Sometimes there is no simple way for doing things.

    I found 3rd party app stealing focus all the time. I have on start up piece of code where I use my main form handle and doing it on separate thread. It all goes fine...if you live app working. But some app for wireless network(found people complaining over net) steals focus. When my app gets focus it somehow can not acquire handle, although my code already pasted that line. Then I get cross-thread in log and hang. If you live app it will hang for 5, 10, 15 sec and continue OK.

    Rewritten that part, removed it, so far so good. 

     

    Monday, June 15, 2015 4:01 AM
  • "Sometimes there is no simple way for doing things"

    Unless you're constrained by a 3rd party library or something like that there's never any reason to have multiple UI threads. If that's what you are doing, it's still unclear.

    "When my app gets focus it somehow can not acquire handle, although my code already pasted that line."

    Are you using something like GetActiveWindow/GetForegroundWindow? In general you should not do that, it's your app, you should now which one is the main form, active window etc.

    Monday, June 15, 2015 4:27 AM
    Moderator