Initialization error - how to prevent
-
Hi all, I'm starting my app (.NET1.1), celebrating good practice, with an info form, which contains nothing but a picturebox and a timer which closes the window after 3 sec. not more. 1000 times it works without problems but sometimes I get the following exception. How do I have to handle such exception ? I have no idea ?
System.TypeInitializationException: Der Typeninitialisierer für System.Drawing.SafeNativeMethods hat eine Ausnahme verursacht. ---> System.Threading.ThreadAbortException: Der Thread wurde abgebrochen.
at System.Drawing.SafeNativeMethods.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Initialize()
at System.Drawing.SafeNativeMethods..cctor()
--- Ende der internen Ausnahmestapelüberwachung ---
at System.Drawing.SafeNativeMethods.CreateIconFromResourceEx(Byte* pbIconBits, Int32 cbIconBits, Boolean fIcon, Int32 dwVersion, Int32 csDesired, Int32 cyDesired, Int32 flags)
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
at System.Drawing.SafeNativeMethods.CreateIconFromResourceEx(Byte* pbIconBits, Int32 cbIconBits, Boolean fIcon, Int32 dwVersion, Int32 csDesired, Int32 cyDesired, Int32 flags)
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
IntPtr CreateIconFromResourceEx(Byte*, Int32, Boolean, Int32, Int32, Int32, Int32)Thank's for help Frank fracalifa
-
Hi all, I'm starting my app (.NET1.1), celebrating good practice, with an info form, which contains nothing but a picturebox and a timer which closes the window after 3 sec. not more. 1000 times it works without problems but sometimes I get the following exception. How do I have to handle such exception ? I have no idea ?
System.TypeInitializationException: Der Typeninitialisierer für System.Drawing.SafeNativeMethods hat eine Ausnahme verursacht. ---> System.Threading.ThreadAbortException: Der Thread wurde abgebrochen.
at System.Drawing.SafeNativeMethods.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Initialize()
at System.Drawing.SafeNativeMethods..cctor()
--- Ende der internen Ausnahmestapelüberwachung ---
at System.Drawing.SafeNativeMethods.CreateIconFromResourceEx(Byte* pbIconBits, Int32 cbIconBits, Boolean fIcon, Int32 dwVersion, Int32 csDesired, Int32 cyDesired, Int32 flags)
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
at System.Drawing.SafeNativeMethods.CreateIconFromResourceEx(Byte* pbIconBits, Int32 cbIconBits, Boolean fIcon, Int32 dwVersion, Int32 csDesired, Int32 cyDesired, Int32 flags)
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
IntPtr CreateIconFromResourceEx(Byte*, Int32, Boolean, Int32, Int32, Int32, Int32)Thank's for help Frank fracalifa
Insufficient data, you might want to show the code. Wild guess: you did use a timer other than Forms.Timer, and its handler is performing an Illegal Cross-Thread operation on a control (probably the InfoForm itself). If correct, the remedy is either use Forms.Timer or read up on Control.Invoke :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Insufficient data, you might want to show the code. Wild guess: you did use a timer other than Forms.Timer, and its handler is performing an Illegal Cross-Thread operation on a control (probably the InfoForm itself). If correct, the remedy is either use Forms.Timer or read up on Control.Invoke :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Here is the code ... nothing spectacular
public class Info_Start : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;public Info\_Start() { // // Erforderlich für die Windows Form-Designerunterstützung // InitializeComponent(); timer1.Interval = 5000; timer1.Start(); this.TopMost=true; } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Info\_Start)); this.timer1 = new System.Windows.Forms.Timer(this.components); // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1\_Tick); // // Info\_Start // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.ClientSize = new System.Drawing.Size(512, 360); this.ControlBox = false; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(520, 368); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(520, 368); this.Name = "Info\_Start"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.TopMost = true; this.Click += new System.EventHandler(this.Info\_Start\_Click); this.Activated += new System.EventHandler(this.Info\_Start\_Activated); } #endregion private void timer1\_Tick(object sender, System.EventArgs e) { this.Close(); } private void Info\_Start\_Click(object sender, System.EventArgs e) { this.Close(); } }
}
that's all ...
-
Here is the code ... nothing spectacular
public class Info_Start : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;public Info\_Start() { // // Erforderlich für die Windows Form-Designerunterstützung // InitializeComponent(); timer1.Interval = 5000; timer1.Start(); this.TopMost=true; } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Info\_Start)); this.timer1 = new System.Windows.Forms.Timer(this.components); // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1\_Tick); // // Info\_Start // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.ClientSize = new System.Drawing.Size(512, 360); this.ControlBox = false; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(520, 368); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(520, 368); this.Name = "Info\_Start"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.TopMost = true; this.Click += new System.EventHandler(this.Info\_Start\_Click); this.Activated += new System.EventHandler(this.Info\_Start\_Activated); } #endregion private void timer1\_Tick(object sender, System.EventArgs e) { this.Close(); } private void Info\_Start\_Click(object sender, System.EventArgs e) { this.Close(); } }
}
that's all ...
fracalifa wrote:
nothing spectacular
I agree. Looks fine at first glance. Now my guess is, when it fails, it is the timer firing before the form has been completely loaded (i.e. in the middle of loading the icon, see StackTraceBack). Remedy might be: wire a Load event and use it to start your timer. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
fracalifa wrote:
nothing spectacular
I agree. Looks fine at first glance. Now my guess is, when it fails, it is the timer firing before the form has been completely loaded (i.e. in the middle of loading the icon, see StackTraceBack). Remedy might be: wire a Load event and use it to start your timer. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi Luc, thank you. I'll try this. Let's see what happens after the 999th start .... :laugh: Frank
Hi Frank, you could make a test setup that creates a new form which selfdestroyes after some time, put everything in a loop, and make the delay a random number say in the range 100...5000 msec (use a static Random !!) then let this run and watch how long it lives on average (say 3 minutes). Now apply my (or other) suggestions to fix, and let the same test run say ten times as long (hence 30 minutes); if that succeeds, you know you have dramatically improved things. The whole process would take no more than 1 hour, and need little or no human intervention. Beats launching it manually 1000 times, and not feeling sure whatsoever... (This is assuming you manage to make the loop fail sooner or later to begin with). :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi Frank, you could make a test setup that creates a new form which selfdestroyes after some time, put everything in a loop, and make the delay a random number say in the range 100...5000 msec (use a static Random !!) then let this run and watch how long it lives on average (say 3 minutes). Now apply my (or other) suggestions to fix, and let the same test run say ten times as long (hence 30 minutes); if that succeeds, you know you have dramatically improved things. The whole process would take no more than 1 hour, and need little or no human intervention. Beats launching it manually 1000 times, and not feeling sure whatsoever... (This is assuming you manage to make the loop fail sooner or later to begin with). :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }