By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,169 Members | 1,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,169 IT Pros & Developers. It's quick & easy.

UI freeze and thread problems

P: n/a
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
Feb 1 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.
--
Stoitcho Goutsev (100)

"Rohit Kumbhar" <ro***********@gmail.comwrote in message
news:em*************@TK2MSFTNGP05.phx.gbl...
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

Feb 1 '07 #2

P: n/a
On 1 Feb, 15:01, Rohit Kumbhar <rohit.kumb...@gmail.comwrote:
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_Unhan dledException);
Feb 1 '07 #3

P: n/a
Stoitcho Goutsev (100) wrote:
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
>
Feb 1 '07 #4

P: n/a
DeveloperX wrote:
On 1 Feb, 15:01, Rohit Kumbhar <rohit.kumb...@gmail.comwrote:
>>[snip]
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_Unhan dledException);
I'll try this. Thanks for the info.
Regards
Rohit
Feb 1 '07 #5

P: n/a
Rohit Kumbhar wrote:
DeveloperX wrote:
>On 1 Feb, 15:01, Rohit Kumbhar <rohit.kumb...@gmail.comwrote:
>>[snip]

AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_Unha ndledException);
I'll try this. Thanks for the info.
Not helping :(

Regards
Rohit
Feb 1 '07 #6

P: n/a
On 1 Feb, 18:54, Rohit Kumbhar <rohit.kumb...@gmail.comwrote:
Rohit Kumbhar wrote:
DeveloperX wrote:
On 1 Feb, 15:01, Rohit Kumbhar <rohit.kumb...@gmail.comwrote:
[snip]
AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);
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.

Feb 1 '07 #7

P: n/a
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
Feb 1 '07 #8

P: n/a
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

Rohit Kumbhar wrote:
Hi,

[]
Using .NET version 2.0 with the latest updates.

What am I missing?

Regards
Rohit
Feb 2 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.