Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys
in my code i am using one infinite loop while(true)
and I have two forms i.e., Form1 and Form2.
Form1 Code.
C#
private void Form1_Load(object sender, EventArgs e)
{
  int32 c=0;
  while (true)
  {
      Form2 fm = new Form2();
      fm.Show();
      c=c+1;
      if(c>1994)
      {
          MessageBox.Show(c.ToString());
      }      
  }
}


But loop suddenly stop after 1993 and it works fine if I uses form1 fm=new form1();
So, can anybody tell me the reason of it ?
Thanks In Advance.
Posted
Updated 24-Jun-15 21:38pm
v2

Seems like homework! The loop does not stop after c greater than 1993 rather a message box starts appearing showing value of c and continue showing it till you kill the application.
 
Share this answer
 
Comments
Member 11024618 25-Jun-15 3:50am    
Actually code never reaches to MessageBox.Show(c.ToString()); if you put break point on it.
Member 11024618 25-Jun-15 3:52am    
Actually code never reaches to MessageBox.Show(c.ToString()); if you put break point on it. So, No message box appears and if you don't put the condition then also it stops after few seconds. Why don't you try?
The code was working fine after 1993 also..(means i m getting the message box pop up
like: 1995,1996 ...and so on)
If the loop stops in your machine then it due to some memory issue as you created 1993 form..
 
Share this answer
 
Comments
Member 11024618 25-Jun-15 4:11am    
Are You Creating the object of form1?
Because it's working fine with form1 object but if I create object of form2 on form1 then it stops and No memory issue.
sasanka sekhar panda 25-Jun-15 4:16am    
No, i tried with form2 object only..and i did not modify any thing with the posted code..But the loop is infinite as expected..
Member 11024618 25-Jun-15 5:44am    
Don't Know but it is not working here. I tried on the other system too.
sasanka sekhar panda 25-Jun-15 5:55am    
what is your system conflagration.. ???
Member 11024618 25-Jun-15 6:07am    
Processor: Intel I3
Ram: 4.00 GB
Hard Disk: 500 GB
Window 7 64-bit
I don't think it's a memory issue since form1 is executing infinite times. But the problem is when I create object of one form in another then it stops automatically. It Works fine when object of form is on same page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900