|
you have been an active member for over a year and should know by now about Google, and CodeProject articles. The solutions can be found everywhere, all it takes is a one-minute search.
|
|
|
|
|
I did search, just didn't know the search criteria,for example "String parsing with maths to int" to me sounded right but google didnt like it.
In the end "String with formula to number" worked but I never usually use the word "formula"
|
|
|
|
|
you are trying to evaluate an expression.
|
|
|
|
|
Hello.
I use VS 2010 C# and try to change Label text (Label is visually created in form editor and has monitoringFile name)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
monitoringFile.Text = @"xxx";
}
This works perfectly, BUT.
If i later decide to change it again as a result of some event (in same Form1 class), the program just exits.
public void CreateFileWatcher(String file)
{
monitoringFile.Text = @"zzz";
}
VS recognizes monitoringFile in both cases and doesnt give error on compile;
Thank you for any help.
|
|
|
|
|
Difficult to tell - it shouldn't "just exit" for any reason - it should give an exception of some form.
Try wrapping your line in a try...catch block and see if any message comes up:
public void CreateFileWatcher(String file)
{
try
{
monitoringFile.Text = @"zzz";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Then tell us what the exception says.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi thank you for your help.
I didn`t look close enough it does output error. (My first day of c#)
<br />
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll<br />
The program '[1844] WindowsFormsApplication1.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).<br />
The program '[1844] WindowsFormsApplication1.vshost.exe: Program Trace' has exited with code 0 (0x0).<br />
|
|
|
|
|
Are you attempting to update the label from the primary thread or a background thread? I suspect you are running this on the background thread, which is a big no-no and should only be done by marshalling the change back to the primary (UI) thread.
|
|
|
|
|
That was pretty much my original thought, but if so then he's playing with some pretty advanced stuff for a first day in C#!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
public void CreateFileWatcher(String file)
Is called as event handler for FileSystemWatcher.
Its my first day of c#, but few years of PHP,javascript,flash so its not entirely new to me.
|
|
|
|
|
Then no, you can't do that. You are not on the GUI thread when the Watcher signals the event.
See Here for what to do.[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Thank you everyone for your help.
|
|
|
|
|
I think I disagree. If you have some prior programming experience, you can easily finish Hello World by noon, and use the rest of the day to discover event handlers; it isn't that hard to stumble on one (timer ticks, serialport received/errors, FileSystemWatcher, etc) at all. Unfortunately the documentation does not clearly state exactly how and when the event handler will execute, and the InvalidOperationException is sufficiently cryptic, so without any help it may be hard to get it working properly before midnight.
|
|
|
|
|
If you aren't using threading (as Pete sugests), then PogoBoy is right - breakpoint the first line in your event handler and single step though. I very much doubt it's the label.Text assignment that is causing the problem, unless threads are involved.
Additionally, go to "Debug" on the Visual Studio menu, select "Exceptions" and make sure everything is ticked - Thrown and Unhandled. That may catch an error earlier, but is a PITA for normal debugging as all exceptions are trapped in the debugger.
A thought occurred - you are running the Debug version of your App, not the Release, aren't you?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I would suggest placing a breakpoint on the first line of your button click event handler and then step through your code step by step to find out exactly why the application is exiting. I have a couple hunches, but without better information, I'd be doing nothing more than guessing. You may find that something entirely different than you expect to be happening. (i.e. I don't think your label is the issue.)
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Yes I did this.
It exits exactly on line with Label changing text.
|
|
|
|
|
Most event handlers are completely asynchronous and execute at a point in time unrelated to what your main thread is doing, so it is pretty natural they run on other threads. Examples are: SerialPort.DataReceived, most timer events, FileSystemWatcher events, etc.
You may want and read this[^] for some experimental proof.
And this[^] for a solution.
|
|
|
|
|
I always hear how VB is soooo verbose and sooooo hard on the eyes... Well I have had it with C# this week.
Please explain to me why in the VB.Net code editor you can select a control on a form from the drop down box on the left and then select the method, etc... that you want to write code for from the drop down on the right and get the shell of the code built for you in the code window, or be taken to where it already exists.
...but in C# all you see in the left drop down in the current parent object that you are in (IE: class, form, etc…) and the right drop down box either only shows you a listing of controls on that form, or methods of the class, but NOT a listing of controls placed on the form?
I don’t get it. What is wrong with the way the VB editor works?
You C# guys need to declare a delegate and attach it to a control, blah blah blah...
All the VB person has to do is select and click and we get the darn code done for us.
Oh yeah, and before you start yelling about connecting multiple handlers to an event, all I have to do in VB is add a Handles clause to the end of my event handler to attach the other control(s) and if I am good, I also modify the name of the method to be more generic, and I am DONE!
Grrrrrrrrrr
Done venting now...
|
|
|
|
|
Are you still using the old crap way of event handling? Haven't you heard of weak events? Oh wait "Handles" doesn't handle that.
|
|
|
|
|
Talk about 'weak events'... I think that pun qualifies
|
|
|
|
|
Totally agree.
Although I'm using more C# than VB.NET I totally agree with Ray, VB.NET editor is superior as far as helping you with the code.
It also shows a comprehensive list of events implemented for that particular control.
Not to mention the right arguments types for the event handler.
|
|
|
|
|
Ray Cassick wrote: drop down box on the left
Ray Cassick wrote: left drop down
Ray Cassick wrote: right drop down box
Ray Cassick wrote: a listing of controls placed on the form
Umm, what? I don't follow. Any VB can do, C# can do better.
|
|
|
|
|
well, there are a couple of differences in the way Visual Studio helps the programmer. In VB.NET the class drop-down (on top of the source edit windows) shows its content hierarchically, so one sees a list of the controls, in C# it doesn't do that, it behaves like a simple ComboBox. Maybe the designers just had some spare time or they thought the VB people needed more help?
|
|
|
|
|
Luc Pattyn wrote: ... or they thought the VB people needed more help?
I think you're on to something, Luc. I've never had problems finding methods and events in C# and never used the drop down in VB.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
|
I only recently changed to C# but was not even aware of the IDE capability, then again I am continually amazed at the shortcuts that I don't know of. Just vetting the way another programmer does their work reveals little insights all the time.
Never underestimate the power of human stupidity
RAH
|
|
|
|