Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Initialization error - how to prevent

Initialization error - how to prevent

Scheduled Pinned Locked Moved C#
helpquestioncsharpgraphicstutorial
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fracalifa
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • F 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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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] }


      F 1 Reply Last reply
      0
      • L Luc Pattyn

        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] }


        F Offline
        F Offline
        fracalifa
        wrote on last edited by
        #3

        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 ...

        L 1 Reply Last reply
        0
        • F fracalifa

          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 ...

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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] }


          F 1 Reply Last reply
          0
          • L Luc Pattyn

            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] }


            F Offline
            F Offline
            fracalifa
            wrote on last edited by
            #5

            Hi Luc, thank you. I'll try this. Let's see what happens after the 999th start .... :laugh: Frank

            L 1 Reply Last reply
            0
            • F fracalifa

              Hi Luc, thank you. I'll try this. Let's see what happens after the 999th start .... :laugh: Frank

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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] }


              F 1 Reply Last reply
              0
              • L Luc Pattyn

                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] }


                F Offline
                F Offline
                fracalifa
                wrote on last edited by
                #7

                Hi Luc, good idea. My feeling is that this could be a runtime problem (loading the relating lib's on the first start). Later the lib's are in the file cache and the problem does not occur. In parallel I will test your suggestion. Thank's Frank

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups