|
Thread.Sleep(100). This worked for me before
|
|
|
|
|
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
1 millisecond = 1000 microseconds...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Look at the FrameworkTimer in the DirectX SDK!
/\ |_ E X E GG
|
|
|
|
|
Althought the QueryPerformanceCounter function does have a resolution of 1 microsecond, you cannot sleep a process that accurately. The best your going to do is 1 millisecond, and even then, the resolution can vary by 10-15 milliseconds due to Windows being a shared system.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
This may seem general but it has happened quite a few times in my month of using C# in Visual Studio.
There are cases where it is obvious that an exception should be thrown, but instead, the program just hangs there and does nothing.
Ex. double[] a = new double[table.Count];
if table is null, it should throw a NullReferenceException. Instead, the program stops and appears to wait indefinitely.
If this phenomenon is common then I hope someone can explain it to me. If not, then please tell me if you have no idea what I'm talking about.
Thanks,
Stanislav
|
|
|
|
|
tachobg wrote:
If this phenomenon is common then I hope someone can explain it to me. I
This is not common. Is Visual Studio hanging or your entire program hanging?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: And in this corner, the Party of Allah
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
No, it's just the program that hangs.
|
|
|
|
|
You could always check to see if the table is null first. Also, is this code inside of a thread or overridden message?
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Yes, you can definitely prevent such exceptions from happening, but when they do happen, they are pretty hard to debug, since it doesn't give you anything to work with -- you don't know the line number or the type of exception.
As for the second question, no it's not.
|
|
|
|
|
What happens when you wrap it in an immediate try catch?
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
It never gets to the catch part...it tries to execute the statement, then it hangs. Really weird.
|
|
|
|
|
What does the following do:
try{
int index = table.Count;
double[] a = new double[index];
}
catch(Exception e1){
...
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Now it throws an exception. Though it seems strange that no exception is thrown just because you have an embedded statement instead of an assignment. I will do some testing to see if this happens in general or just in my program.
Thanks to everyone for their help.
|
|
|
|
|
As I expected it does exactly as it should outside the context of my program
|
|
|
|
|
Hi,
I was wondering if I could open a MainMenu menu via code?
.NET 1.1
Thanks,
Ron
-- modified at 14:14 Monday 14th August, 2006
|
|
|
|
|
Hi,
I have a process called from a main application, which invokes another 3rd party excutable program having its own UI. The main application has to wait untill the process finishs. My code is:
<br />
process1.StartInfo.FileName = exeFile;<br />
process1.StartInfo.Arguments = argFile;<br />
process1.Start();<br />
process1.WaitForExit();<br />
I hope the 3rd party program will run as a model dialog, but when it's running, the background main application UI can't be seen. Any way to refresh the main application so that user can see its UI when running 3rd party program?
Thanks.
-- modified at 16:12 Thursday 17th August, 2006
|
|
|
|
|
First, place the code above into its own thread. When WaitForExit returns, use Control.Invoke to send a message back to the UI thread. To stop the user from being able to interact with the application, set the form's Enabled property to false , then set it to true when the third-party program exits.
|
|
|
|
|
Hi Mike,
Thanks for your reply. I'm still not sure where to use Control.Invoke. Here is my code:
<br />
private void mainFrameButton_Click(object sender, EventArgs e)<br />
{<br />
ThreadStart worker = new ThreadStart(WorkerThreadMethod);<br />
Thread t = new Thread(worker);<br />
t.Start();<br />
<br />
this.Invoke(worker);<br />
this.Enabled = false;<br />
}<br />
<br />
public void WorkerThreadMethod()<br />
{ <br />
this.process1.StartInfo.FileName = ExeFile;<br />
this.process1.StartInfo.Arguments = ArgFile;<br />
this.process1.Start();<br />
this.process1.WaitForExit();<br />
}<br />
<br />
private void process1_Exited(object sender, EventArgs e)<br />
{<br />
this.Enabled = true;<br />
}<br />
It didn't work, and the worse thing is the third-party program poped up twice, and even it's closed, the main application UI was still disabled.
Some help please? Thanks.
|
|
|
|
|
i use list view that have control in this page
http://www.codeproject.com/cs/miscctrl/ListViewEmbeddedControls.asp
* if i have database with 3 recode ex:
------
field 1
------
5
7
8
-----
i want to add 3 row in the listView with first colum must be button(ClickMe)
the problem new
-----------------
1 - how i make my app when i click in the fisrt (ClickMe) button -> open new Form with 5 as parameter - > new Form(5);
and second button new Form(7);
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
enum MyTemp
{
cold = 0,
fp = 32
}
day1Miles.Text = textBox1.Text;
}
I get an error on 2 ( error says: } expected )
What am I missing in the concepts here? Why can't I define an enumerated constant at top of the button click? I can replace the enum statement with something like int cold = 0; and it works fine, so why can't I put an enum statement here?
For example this compiles without error:
private void button1_Click(object sender, EventArgs e)
{
int cold = 0;
day1Miles.Text = textBox1.Text;
}
-- modified at 12:49 Monday 14th August, 2006
|
|
|
|
|
Try defining the enum outside of your function.
|
|
|
|
|
Defining the enum outside the function is exactly what is needed, but I just don't understand why I would need to define the enum outside of the function.
|
|
|
|
|
Because it is pointless to define the enum in that scope. It wouuld only be valid for the scope of the function, and useless outside of it (you could not pass in a parameter of the enum type, nor return a an object of the eunum's type.
|
|
|
|
|
Thank-you for trying to help, but I am still confused....
Maybe here are some better examples of my dilema in undertanding where I can define an enum? I know I can make the example work by moving where the enum is defined, but I still do not understand why it needs to be moved. Why can't the enum constant be used just like a symbolic constant as my examples below demonstrate?
This does NOT work..... I would think it would, and still cannot understand why not.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
enum temps
{
cold = 0,
fp = 32
}
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
But the following does compile...
namespace ConsoleApplication2
{
class Program
{
enum temps
{
cold = 0,
fp = 32
}
static void Main(string[] args)
{
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
And this works, if ditch the idea of using an enum, and use named constants
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int cold = 0;
int fp = 32;
System.Console.WriteLine("freezing is {0}", cold);
}
}
}
|
|
|
|