UI freeze and thread problems

R

Rohit Kumbhar

Hi,

I am writing a Windows Forms C# application [I am new to C#] for reading
files on the disk. My problem is the UI freezes when restored after
being minimized for a long time [20-30 minutes].

I have a separate thread which does the reading and updates the UI [two
datagridviews, two labels and a button control]. I ran against the cross
thread UI calls when debugging and corrected the error by using
delegates and "InvokeRequired" property.

Running the application in Debug mode and checking for cross thread call
exception is the test I am using for checking this.

Another issue that I am facing is the dieing/killing of the reading
thread. No exceptions. No event logs. The thread just dies, I can't
understand why. The UI freeze and thread dying usually happen together.
I am doing GC.Collect(), Application.DoEvents() and Thread.Sleep(200)
after every file read and processed. For a try, I wrote the handler for
GotFocus event of the form to explicitly invalidate the controls.
Doesn't help.

My biggest problem is all this happens randomly, not for a particular
file or file type.

Using .NET version 2.0 with the latest updates.

What am I missing?

Regards
Rohit
 
S

Stoitcho Goutsev \(100\)

Rohit,

Without a sample code to test against it will be really difficult for one to
tell what the problem is unless one has had the same problem before. I know
that it is not easy to write a sample for a program like yours, but this
maybe this is the only way you can get help from this ng.
 
D

DeveloperX

Hi,

I am writing a Windows Forms C# application [I am new to C#] for reading
files on the disk. My problem is the UI freezes when restored after
being minimized for a long time [20-30 minutes].

I have a separate thread which does the reading and updates the UI [two
datagridviews, two labels and a button control]. I ran against the cross
thread UI calls when debugging and corrected the error by using
delegates and "InvokeRequired" property.

Running the application in Debug mode and checking for cross thread call
exception is the test I am using for checking this.

Another issue that I am facing is the dieing/killing of the reading
thread. No exceptions. No event logs. The thread just dies, I can't
understand why. The UI freeze and thread dying usually happen together.
I am doing GC.Collect(), Application.DoEvents() and Thread.Sleep(200)
after every file read and processed. For a try, I wrote the handler for
GotFocus event of the form to explicitly invalidate the controls.
Doesn't help.

My biggest problem is all this happens randomly, not for a particular
file or file type.

Using .NET version 2.0 with the latest updates.

What am I missing?

Regards
Rohit

Are you using BeginInvoke when working with the controls on the UI
thread? or just changing properties?

Have you added a a domain unhandled exceptioin handler?

AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
 
R

Rohit Kumbhar

Stoitcho said:
Rohit,

Without a sample code to test against it will be really difficult for one to
tell what the problem is unless one has had the same problem before. I know
that it is not easy to write a sample for a program like yours, but this
maybe this is the only way you can get help from this ng.

I really wanted to paste/attach the whole code here but I really need to
get some pieces out. I'll do thatASAP. Thanks
 
R

Rohit Kumbhar

DeveloperX said:
Are you using BeginInvoke when working with the controls on the UI
thread? or just changing properties?

I'm sorry, I didn't get this properly. This is a method that I use to
update the file count.

--><--
private void UpdateTotalFileCount(int number) {

if (this.lblFilesCount.InvokeRequired) {

UpdateTotalFileCountCallback rem = new
UpdateTotalFileCountCallback(UpdateTotalFileCount);

this.Invoke(rem, new object[] { number });

} else {
this.lblFilesCount.Text = "Files searched : " + (number);
this.lblFilesCount.Update();
}
}

--><--

UpdateTotalFileCountCallback is my delegate and I call the function
UpdateTotalFileCount(++numberOfFiles) from the separate thread.

Have you added a a domain unhandled exceptioin handler?

AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
I'll try this. Thanks for the info.


Regards
Rohit
 
D

DeveloperX

Rohit said:
DeveloperX said:
[snip]
AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
I'll try this. Thanks for the info.

Not helping :(

Regards
Rohit

:( Did you add a method CurrentDomain_UnhandledException? Sorry if
this is obvious, best to check.
 
R

Rohit Kumbhar

DeveloperX wrote:
[]
:( Did you add a method CurrentDomain_UnhandledException? Sorry if
this is obvious, best to check.
Oh yes! I added code to make entries into the event viewer.

Regards
Rohit
 
R

Rohit Kumbhar

This is looking like a datagridview refresh problem. The datagrid view
is readonly and causing the freeze while redrawing. I am reproducing the
situation by changing the display settings.
Does anybody have any suggestions/hacks?

Regards
Rohit
 

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