473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

enableVisualstyles -> Crash

Hi,

everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if
this is of interest.

Best regards,

Martin
Nov 16 '05 #1
5 3356
mphanke wrote:
Hi,

everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if this
is of interest.


After you enable it do: Application.DoEvents();

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #2
Hi,

Thanks for the hint, but didn't help!

So my Main() looks like :

static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}

The func which starts the thread and displays the progress bar looks like:

Thread g_Thread;

private void ShowProgressBar()
{
DataProgress dp = new DataProgress(true); // true->start the timer
immediately
try
{
dp.ShowDialog();
dp.Activate();
}
catch(ThreadAbortException abortException)
{
dp.StopTimer(); // stop the timer
dp.SetTitle((string)abortException.ExceptionState) ; // set this to be
the final message
dp.Close(); // close -> and crash if visualstyles enabled ->
WindowsFormsParkingWindow
}
}

private void StartStopThread(bool b, string str)
{
if(b)
{
g_Thread = new Thread(new ThreadStart(ShowProgressBar));
g_Thread.Start();
Thread.Sleep(250);
}
else
{
if(g_Thread.IsAlive)
{
g_Thread.Abort(str);
Thread.Sleep(250);
}
}
}

Hope this makes things clearer now.

Martin

Frans Bouma [C# MVP] wrote:
mphanke wrote:

Hi,

everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if this
is of interest.

After you enable it do: Application.DoEvents();

FB

Nov 16 '05 #3
You did not provide a complete code sample so it's hard to tell what's
really going on.

I'd be surprised if the thread that the function ShowProgressBar executes on
behaves as you think it does. Just because you catch a ThreadAbortException
does not mean that you've handled it completely. After the catch block
completes the runtime will rethrow the exception again unless you call
ResetAbort. If you do not call ResetAbort then eventually that entire thread
of execution will terminate and you will see an unhandled exception - if
this was the main thread of execution then your app crashes.

Another potential problem is that you may be updating controls on threads
other then the thread on which the control was created.

In general, don't abort a thread unless you know what all the side effects
are. There are other and better ways to cause a thread to terminate in a
graceful manner. Also, controls should usually be updated on the same thread
that created them. You can use the Control.InvokeRequired field to test for
this.

"mphanke" <mp*****@nospam.nospam> wrote in message
news:e3*************@TK2MSFTNGP12.phx.gbl...
Hi,

Thanks for the hint, but didn't help!

So my Main() looks like :

static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}

The func which starts the thread and displays the progress bar looks like:

Thread g_Thread;

private void ShowProgressBar()
{
DataProgress dp = new DataProgress(true); // true->start the timer
immediately
try
{
dp.ShowDialog();
dp.Activate();
}
catch(ThreadAbortException abortException)
{
dp.StopTimer(); // stop the timer
dp.SetTitle((string)abortException.ExceptionState) ; // set this to be
the final message
dp.Close(); // close -> and crash if visualstyles enabled ->
WindowsFormsParkingWindow
}
}

private void StartStopThread(bool b, string str)
{
if(b)
{
g_Thread = new Thread(new ThreadStart(ShowProgressBar));
g_Thread.Start();
Thread.Sleep(250);
}
else
{
if(g_Thread.IsAlive)
{
g_Thread.Abort(str);
Thread.Sleep(250);
}
}
}

Hope this makes things clearer now.

Martin

Frans Bouma [C# MVP] wrote:
mphanke wrote:

Hi,

everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if thisis of interest.

After you enable it do: Application.DoEvents();

FB

Nov 16 '05 #4
Hi,

thanks, this was the advice I needed. The problem was I called
Application.DoEvents() inside the Tick-func of the Timer. This actually
caused the crash on the Close()-call.

Martin

David Levine wrote:
You did not provide a complete code sample so it's hard to tell what's
really going on.

I'd be surprised if the thread that the function ShowProgressBar executes on
behaves as you think it does. Just because you catch a ThreadAbortException
does not mean that you've handled it completely. After the catch block
completes the runtime will rethrow the exception again unless you call
ResetAbort. If you do not call ResetAbort then eventually that entire thread
of execution will terminate and you will see an unhandled exception - if
this was the main thread of execution then your app crashes.

Another potential problem is that you may be updating controls on threads
other then the thread on which the control was created.

In general, don't abort a thread unless you know what all the side effects
are. There are other and better ways to cause a thread to terminate in a
graceful manner. Also, controls should usually be updated on the same thread
that created them. You can use the Control.InvokeRequired field to test for
this.

"mphanke" <mp*****@nospam.nospam> wrote in message
news:e3*************@TK2MSFTNGP12.phx.gbl...
Hi,

Thanks for the hint, but didn't help!

So my Main() looks like :

static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}

The func which starts the thread and displays the progress bar looks like:

Thread g_Thread;

private void ShowProgressBar()
{
DataProgress dp = new DataProgress(true); // true->start the timer
immediately
try
{
dp.ShowDialog();
dp.Activate();
}
catch(ThreadAbortException abortException)
{
dp.StopTimer(); // stop the timer
dp.SetTitle((string)abortException.ExceptionStat e); // set this to be
the final message
dp.Close(); // close -> and crash if visualstyles enabled ->
WindowsFormsParkingWindow
}
}

private void StartStopThread(bool b, string str)
{
if(b)
{
g_Thread = new Thread(new ThreadStart(ShowProgressBar));
g_Thread.Start();
Thread.Sleep(250);
}
else
{
if(g_Thread.IsAlive)
{
g_Thread.Abort(str);
Thread.Sleep(250);
}
}
}

Hope this makes things clearer now.

Martin

Frans Bouma [C# MVP] wrote:
mphanke wrote:

Hi,

everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if
this
is of interest.
After you enable it do: Application.DoEvents();

FB


Nov 16 '05 #5
mphanke <mp*****@nospam.nospam> wrote in
news:e3*************@TK2MSFTNGP12.phx.gbl:
Hi,

Thanks for the hint, but didn't help!

So my Main() looks like :

static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}

The func which starts the thread and displays the progress bar
looks like:

Thread g_Thread;

private void ShowProgressBar()
{
DataProgress dp = new DataProgress(true); // true->start
the timer
immediately
try
{
dp.ShowDialog();
dp.Activate();
}
catch(ThreadAbortException abortException)
{
dp.StopTimer(); // stop the timer
dp.SetTitle((string)abortException.ExceptionState) ; //
set this to be
the final message
dp.Close(); // close -> and crash if visualstyles
enabled ->
WindowsFormsParkingWindow
}
}

private void StartStopThread(bool b, string str)
{
if(b)
{
g_Thread = new Thread(new
ThreadStart(ShowProgressBar)); g_Thread.Start();
Thread.Sleep(250);
}
else
{
if(g_Thread.IsAlive)
{
g_Thread.Abort(str);
Thread.Sleep(250);
}
}
}


Martin,

Threading and WinForms can get tricky. You may need to spawn the new
thread with your form's BeginInvoke method rather than using the
Thread class. See this article for more info (it's the first in a
series of three):

http://msdn.microsoft.com/library/en-
us/dnforms/html/winforms06112002.asp

or

http://tinyurl.com/29sd

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: #ROBERT | last post by:
(VS 2003 + .NET Framework 1.1 + WinXP Pro SP2) Calling Application.EnableVisualStyles() after the initialization() removes all images in the tab control (in the tab headers I mean). Without...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
1
by: desa | last post by:
If I call EnableVisualStyles none the images in my ImageLists show up in my controls anymore. Is this a known issue? How do I fix this? I'm using VS.NET 2003.
4
by: Christian Westerlund | last post by:
Hi! I usually enable visual styles in my apps. I do it in Main before I start my app with Application.Run. Today when I changed from debug to release mode in Visual Studio .NET 2003, the...
8
by: perspolis | last post by:
hi all I can't use the Application.enableVisualStyle method. it gives me an error that it can't find a match for it. I installed dotnet version 1.1..but it still dosen't work..????
17
by: Lance | last post by:
I've noticed that calling DoEvents is much slower in an application that has called Application.EnableVisualStyles in Sub Main. Furthermore, the performance seems to worsen each time that DoEvents...
2
by: Juan Pedro Gonzalez | last post by:
I am a bit unsure about this "Effect"... My code: Public Sub Main() Application.EnableVisualStyles() Application.DoEvents() Dim myMainForm As New FormularioPrincipal Dim mySplash As New...
3
by: Michael A. Covington | last post by:
I added Application.EnableVisualStyles() as the first statement in Main() of my program, and didn't notice much change in visual appearance, but what I *did* notice is that some of my buttons...
3
by: Michael A. Covington | last post by:
Further to previous post... I have a big, complex program which works fine as long as I don't call EnableVisualStyles. If I do this: Application.EnableVisualStyles();...
7
by: Peter | last post by:
Hello, I'm using Visual Studio 2003 and it would be nice if my buttons and other controls could look like Windows XP buttons rather than the flat square kind. I looked on the web and found some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.