|
You need to throw a new exception to preserve Inner Exceptions:
Try This:
try
{
Function();
}
catch(Exception ex)
{
throw new Exception("Your new error message", ex);
}
Hope this helps.
|
|
|
|
|
Documentation states that throw preserves stack trace and throw e does not.
You approach incurs handling of the inner exceptions.
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: throw e does not
incorrect.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Dear All,
I have a query in teechart.
I have created a horizontal bar chart in C# using tee chart. Now i want to change the color of the bar depending on its value(e.g. green color for positive value & red for negative).
any settings in the property?
can anyone give solution on this?
thnx
|
|
|
|
|
Hello all,
Many times during working on web projects I come across handling the customized search page for comodity. Many times it contains 10 to 20 fields which is quite a good number to pass another page and to code.
I want to know if there is any efficient way to handle such situations.
Thanks
|
|
|
|
|
Hi!!
I dint know where to post it...
But i want to know which Application of Windows responds to Win +D (used to view Desktop) and other such combinations??
Ayan
|
|
|
|
|
Windows Explorer I'd say. How is this a C# question?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
tell me where shud i post this question...
One more thing...
Windows Explorer(explorer.exe) can read all the keystrokes??
How is this whole process is working???
Can u plz explain...
I'm just curious...
|
|
|
|
|
Windows can react to specific key combinations, known as hotkeys or hooks. Google these terms. And have a look at functions such as RegisterHotKey and http://support.microsoft.com/kb/318804[^]. Explorer must be using one of those.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks...
But i dint get anywhere...
Thanks anyway...
|
|
|
|
|
Hi!!
I wanna code a method that can restart the application without any user involvment..
I mean when an error is encountered, the method can be used to restart the application..
Plz help me out...
|
|
|
|
|
You can use following code to do so
Application.Exit();
Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id);
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
How will it work can u plz explain..
i mean after this Application.Exit(); how will Process.Start(...); will be executed???
|
|
|
|
|
Ok its working....
Thanks for this...
But will it work on a Console Application too...
I cudnt find this Application...
How shud i integrate it in my code??
Its not exiting but ya its opening another instance...
How shud i get it working...
|
|
|
|
|
Try following code
Close();
System.Diagnostics.Process.Start(Application.ExecutablePath);
or you can also do following
Add using System.Windows.Forms; to the top and call
Application.Restart();
You may need to add the reference: "System.Windows.Forms.dll" to your project.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Close() cant be used... m using Visual Studio 2010 n its not allowing... I mean its giving error...
And Application.Restart() is working fine but it aint closing the previous instance...
How shud i close the console window forcibly.. Should i use Process.Kill()??
|
|
|
|
|
Ya you can also go for kill method to kill your process...
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
To kill the application i've used
Process.GetCurrentProcess().Kill();
To restart
{
Process.Start(Application.ExecutablePath, "/restart" + Process.GetCurrentProcess().Id);
Process.GetCurrentProcess().Kill();
}
Thanks for the help...
If u can find anyother more appropriate way plz let me know...
Ayan
|
|
|
|
|
Application.Restart();
stops the current process and starts a new identical one.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
This one wont work in console application...
this will open a new instance of the application but cant close the current instance...
|
|
|
|
|
How was Luc supposed to know it was a Console application? You didn't volunteer this info up front.
|
|
|
|
|
|
Hello Everybody,
I am continue my question and it's answer with a new problem.
My New Problem is : I have two Notepad First One is in Hindi Keyboard Language and Second is Abrahic. Now I am
Trying to Hook Keycode. But I am not able to check the Active Windows Keyboard Layout.
My Previous Questions is:
http://www.codeproject.com/Messages/3753244/Keyboard-Language-and-Settings.aspx[^]
It's Answer is : Unicode Capturing
If you can think then I Can.
|
|
|
|
|
Please pay attention to the following code:
Note: Thread t;
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
t = new Thread(new ThreadStart(main));<br />
t.Start();<br />
<br />
Thread.Sleep(1000);<br />
<br />
t = new Thread(new ThreadStart(main));<br />
t.Start();<br />
}<br />
<br />
public void main()<br />
{<br />
int x, y, a, b;<br />
double selectY;<br />
Random rnd = new Random();<br />
<br />
x = rnd.Next(0, lblEnvironment.Width - 20);<br />
<br />
Thread.Sleep(100);<br />
y = rnd.Next(0, lblEnvironment.Height - 20);<br />
<br />
if ((x > -20) && (x < lblEnvironment.Width))<br />
{<br />
Thread.Sleep(100);<br />
selectY = rnd.NextDouble();<br />
<br />
if (selectY < 0.5)<br />
y = -20;<br />
else<br />
y = lblEnvironment.Height;<br />
}<br />
<br />
a = rnd.Next(-5, 5);<br />
Thread.Sleep(100);<br />
b = rnd.Next(-5, 5);<br />
<br />
while (a == 0) a = rnd.Next(-5, 5);<br />
while (b == 0) b = rnd.Next(-5, 5);<br />
<br />
Pen pen = new Pen(Color.Red, 10);<br />
Graphics g = lblEnvironment.CreateGraphics();<br />
<br />
while (true)<br />
{<br />
if (cancelThread)<br />
{<br />
cancelThread = false;<br />
t.Abort();<br />
}<br />
<br />
g.DrawEllipse(pen, x, y, 20, 20);<br />
<br />
Thread.Sleep(100);<br />
g.Clear(Color.White);<br />
<br />
if (((x < 0) && (a < 0)) || ((x == lblEnvironment.Width) && (a > 0)))<br />
a *= -1;<br />
x += a;<br />
<br />
if (((y < 0) && (b < 0)) || ((y == lblEnvironment.Height) && (b > 0)))<br />
b *= -1;<br />
y += b;<br />
<br />
if ((x > lblEnvironment.Width - 25) || (x < 5))<br />
{<br />
t = new Thread(new ThreadStart(main));<br />
t.Start();<br />
<br />
Thread.CurrentThread.Abort();<br />
}<br />
<br />
if ((y > lblEnvironment.Height - 25 && b > 0) || (y < 5 && b < 0))<br />
{<br />
b *= -1;<br />
}<br />
}<br />
}
The scenario is as bellow:
At the beginning of the program two balls are appeared as 'Thread' and they start to move in various directions. If each one of them hit to the left or right wall then that ball must disappear and a new ball as 'Thread' must enter and this routine should be continued to the end. Currently everything is correct but the problem is that it seems both of balls use one resource (variables) and because of this are displayed blinking. What should I do to solve the problem?
Thank you
|
|
|
|
|
Hi,
for starters, please use PRE tags rather than CODE tags; they preserve formatting and indentation, making it all much more readable (you could still edit the existing message!).
You have two threads executing the same code, no problem. Each of them has a main method with local variables on the stack, they will be distinct as each thread has its own stack.
You may have a problem due to the way instances of Random are seeded: if you don't provide an explicit seed, they derive one from the current time, however your non-commented Sleep(1000) probably takes care of that.
You do have a problem with the way you do your painting. I'm not going to explain all the things you did wrong, I suggest you read this little article[^].
One more comment: your objects could also hit each other, something your code is never going to detect as the bouncing balls have their state completely private.
Suggestion 0: modify all painting stuff, in accordance with the guide lines set out in my article.
Suggestion 1: create a Ball class, have it hold the state and all the code a ball requires; then instantiate two (or more) of them, and keep them in a generic list. If you use threads, hide them inside the Ball class.
Suggestion 2: you don't really need a new ball and thread when the current ball leaves the valid x-range; you could recycle the ball, give it a new location, direction, speed, what have you, and save on the system resources (threads are expensive, and aborting them isn't very nice).
Suggestion 3: you don't really need a thread for each ball, a single timer could be used to update each of the balls.
Suggestion 4: create some global way to detect collisions, it will need information about all walls and balls.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|