VB.net windows app freezing after screen saver exits

S

Steve

Hi All

I have found that if my windows forms app (VS 2008) is minimised when the
screen saver cuts in,
then when the screen saver exits, my application icon on the task bar won't
respond, i.e the application form doesn't appear again

The task bar icon just flashes orange when you click it

I have tried ctrl-alt-delete to get task manager and clicked 'Switch to'. My
app partially restores (1/2 displayed) but then the whole screen freezes

I have to kill the process and restart my app

This happens regularly

Has anybody experienced this

How can I tell what is causing it, as there is nothing in the Windows event
logs or my app log


Regards
Steve
 
L

Lingzhi Sun [MSFT]

Hi Steve,

Could you please let me know whether the issue happened only on a specific
VB.NET WinForm application or on all the VB.NET WinForm applications even
C# WinForm applications? Please also create a new VB.NET Windows Forms
application and tell me whether the issue occurs on the application.

If the problem only occurs on some specific application, could you please
provide us with more detailed information about this application? Does it
have some specific logic for message handling?

Besides, I think the following information are also very important for this
issue, the operation system version and whether Visual Studio has installed
the Service Pack 1. I am really appreciated if you can provide us with
these information.

Thank you very much & Have a nice weekend, Steve!


Best Regards,
Lingzhi Sun
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Johnny Jörgensen

Hi Steve

This is a long shot - I haven't investigated the matter more closely. But
could it be something like this...?

Updating the UI could be dependent on fetching information from a remote
drive (either network or internet), and the screensaver cuts the remote
connections (I don't know if this is the case, but you never know) causing
your app to freeze.

If this is the case, you would probably need to insert a loop that tries to
update whatever should be updated for a while (until the connection needed
is reset).

Also, have you tried testing if your app is responsive WHILE the screensaver
is active? - Of course you can't see that directly, but maye you could try
inserting a timer routine that can write a logging message to a file every
second or so?

Just ideas - they might be stupid, but there's not much to go on. It would
be valuable information to know what the app actually does while it is
minimized and what it's supposed to do when it is restored again.

Best regards,
Johnny J.
 
S

Steve

Hi Lingzhi

Thanks for the reply

I found what the issue is but don't know why it is happening

I have found that 1 Devexpress dll and the MS Reportviewer dll take some
time to load into memory the first time they are needed, which results in
several seconds delay before my windows form, containing components from the
2 dlls, appears

From then on the forms load quickly as the dlls are already loaded in memory

To try to improve this I had attempted to preload the assembly dlls as my
application starts

I did it in a backgroundworker as follows

Private Sub bwpreload_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bwpreload.DoWork
Dim frm As Form, frm2 As Form
Try
frm = New frmemail
frm2 = New frmreporting
frm.Close()
frm2.Close()
Catch ex As Exception
savetolog("bw_pre", ex.Message.ToString)
Finally
If Not IsNothing(frm) Then
frm.Dispose()
End If
If Not IsNothing(frm2) Then
frm2.Dispose()
End If
End Try
End Sub

This solved the issue of the slow first run of 2 of my windows forms

The problem is when my screen is minimised and the screen saver cuts in then
I can't get my application to reshow itself as originally explained

Removing the backgroundworker code solves the issue

This only happens when my application is minimsed. If it is full screen and
the screen saver cuts in there is NO problem

I am using VS2008 SP1 and XP SP2. It also happens on W2k3 Server

Regards
Steve
 
L

Lingzhi Sun [MSFT]

Hi Steve,

Thank you for providing us with the detailed information!

I tried the similar logic to load Microsoft.ReportViewer.WinForms.dll and
Microsoft.ReportViewer.Common.dll in BackgroundWorker (Windows XP SP2 and
Visual Studio 2008 SP1), but I did not reproduce the issue. I think we
can first check whether the issue is caused by the dlls. Devexpress.dll
looks like a third party assembly. Could you please try to load some
other .NET Framework assemblies instead of the above two dlls in
BackgroundWorker and see whether the problem exists?

In other hand, BackgroundWorker uses .NET thread pool. Please try to
create a .NET Threading.Thread to preload the assemblies, so that we can
avoid the problem of the BackgroundWorker. Besides, instead of creating
some Windows Forms in the BackgroundWorker, could you please also try
directly loading the assemblies by Assembly.Load or Assembly.LoadFrom?

Last but now least, I think John’s idea is very good that we can log the
application activities when screensaver starts. With the logging, we can
detect whether the application is freezing during the screensaver exists.

The above testing results are really important to troubleshoot the issue.
Thank you very much and looking forward to your post.

Have a nice day, Steve and John!


Best Regards,
Lingzhi Sun
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
S

Steve

Hi Lingzhi, John

I tried loading frmreporting only in backgroundworker (same code) which has
NO devexpress components and NO Problems after screen saver exited

I tried loading frmemail in backgroundworker (same code) which has
devexpress components and the application froze when screen saver exited
I put a timer in the application main form, as John suggested, which wrote
to a log every 2 seconds and found NO entries in the log whilst frozen
i.e the whole application was frozen

I deleted the backgroundworker and used threading as you suggested via
Dim t As New Thread(AddressOf preloaddlls)

t.Start()

preloaddlls has exact same code as I originally sent.....

Private sub preloaddlls
Dim frm As Form, frm2 As Form
Try
frm = New frmemail
frm2 = New frmreporting
frm.Close()
frm2.Close()
Catch ex As Exception
savetolog("bw_pre", ex.Message.ToString)
Finally
If Not IsNothing(frm) Then
frm.Dispose()
End If
If Not IsNothing(frm2) Then
frm2.Dispose()
End If
End Try
end sub

Problem Solved. Application did not freeze after screen saver exited

Questions
1. When you create a thread as above, do you have to destroy it after it has
finished running the preloaddlls sub ?
2. Is Assembly.load a better option and if so does it load any dependencies
as well, or do you have to load all dependencies specifically?

Any way
Thanks for your assistance with this issue

Regards
Steve
 
L

Lingzhi Sun [MSFT]

Hi Steve,

From your description, the issue might be caused by the Devexpress.dll.
Also I think the application’s UI thread is frozen when the screensaver
starts. To make sure whether the UI thread is frozen, please use a
Threading.Timer to write some logs instead of calling the
Windows.Forms.Timer, because if the UI thread is hang, a
Windows.Forms.Timer cannot work either. To troubleshoot the root cause of
the issue, we can also use Process Explorer to check the callstack of the
UI thread. Here is some references:
http://www.technochakra.com/profiling-with-procexp-process-explorer/.

For the two follow up questions:

Question 1: We don’t need to destroy the thread manually after it
finishes running the thread proc. After the thread callback finishes, the
thread is ended. CLR will help us to destroy the stopped thread. Here
is a very helpful series articles introducing .NET threading,
http://www.albahari.com/threading/.

Question 2: If the form’s constructor has some other code logic that you
need to call when the application starts, I think your method to create the
forms is fine. Otherwise, if you only need to preload the assemblies into
AppDomain, I think directly calling Assembly.Load is more efficiency.
Also it will load the dependencies as well. However, please note that CLR
has optimize the assembly loading process and if the dependency assemblies
are not invoked, these assemblies will be delay loaded (be loaded if
necessary). So to make sure all the dependency assemblies are also
loaded, we can use the following code logic:
============================================
Dim ass As Assembly = Assembly.Load("AssemlyName")
Dim assName = ass.GetReferencedAssemblies()
For Each a In assName
Assembly.Load(a)
Next
============================================

Besides, here are some references about the differences among
Assembly.Load, Assembly.LoadFrom, and Assembly.LoadFile:
http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx
http://blogs.msdn.com/suzcook/archive/2003/09/19/57248.aspx
http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx


Have a nice day, Steve!


Best Regards,
Lingzhi Sun
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
M

Mark Hurd

Steve said:
Hi All

I have found that if my windows forms app (VS 2008) is minimised when
the screen saver cuts in,

One thing I haven't seen asked is "What is the screensaver?" Try the
simple Blank Screen and see if the problem still occurs.

If not there is some interaction with the screensaver and DevExpress
(according to your other responses).

If it does still occur, and in any case, you need to ask DevExpress.
They have a good support website
http://www.devexpress.com/Support/Center/SearchResults.aspx?searchtext=screensaver&p=T4|P0|0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top