|
The only whay that it doesn't throw you is that you either used try catch to handle error or that control is created on a same thread as thread that is modifying your control. You can check AnyControl.InvokeRequired proprty
|
|
|
|
|
some Control operations are harmless and work across threads without causing an exception; example: reading Label.Text.
As this is undocumented, you should not rely on it.
I collected the most relevant information here[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
There is a setting you could check:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.checkforillegalcrossthreadcalls.aspx
Interesting, according to that page exceptions are only thrown if debugging (which I hadn't realised). Are you debugging?Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: exceptions are only thrown if debugging
Didn't know that and so I checked it with a Threading.Timer modifying a Label.Text;
throws an exception inside Visual Studio; however even a debug build will not throw an exception if run outside Visual Studio.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi,
Why we do always associate events with delegates? Why a normal function cannot be called when an event fires ? What is the advantage here when delegates are called when an event fires ?
Thanks
|
|
|
|
|
Rahul Babu wrote: Why we do always associate events with delegates
Because a code needs to be called to do something, otherwise handling the event would be pointless, and calling methods fits this bill.
Rahul Babu wrote: Why a normal function cannot be called when an event fires ?
What exactly do you mean by "Normal Function"? if you mean void Foo() then this is legitimate:
public class Bar
{
event Action MyEvent;
void Foo()
{
}
public Bar()
{
MyEvent += Foo;
}
} Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
|
Rahul Babu wrote: Why a normal function cannot be called when an event fires
How will the event know that you want it to call that function?
|
|
|
|
|
It seems people disagree..
I don't see why.
Surely if you just "have a method" and you "have an event", that event doesn't magically know to invoke that method. You'd have to tell it that first, and then you have a delegate (even if you use the shorthand syntax, a delegate object is still constructed)
|
|
|
|
|
delegates are like variables. Except that they refer to a method.
During the designing of events, you do not know what method will be called when this event is raised. Hence we use a delegate. The class checks if the delegate is allocated. If yes, then raise the event otherwise don't.
|
|
|
|
|
Because events are delegates -- multi-cast delegates.
Rahul Babu wrote: Why a normal function cannot be called
An instance of a delegate type is just a reference to a "normal function"; there is nothing especially magical about delegates.
|
|
|
|
|
The others have answered pretty well, but I'd like to point out that events do differ from delegates somewhat:
1) Events must be public.
2) Events can only be called by the class they are declared on.
3) Events must have a certain signature (e.g., a sender and a parameter derived from EventArgs).
I could be wrong on that last one, but I seem to remember reading something like that.
EDIT: The first and last items were both incorrect.
|
|
|
|
|
aspdotnetdev wrote: 3) Events must have a certain signature (e.g., a sender and a parameter derived from EventArgs).
Not true. You can create you own events using any parameters you want, standard classes or custom, or even no parameters at all.
I might be thinking of the handler has to have the exact same signature as that specified by the event definition.
|
|
|
|
|
Quite right (just tried it). I must have just been reading about the style Microsoft uses for all their events.
|
|
|
|
|
1) Incorrect, they can use any of the normal access modifiers
3) As you've already discovered below, also incorrect... the can have any signature and even a return type!
|
|
|
|
|
DaveyM69 wrote: Incorrect, they can use any of the normal access modifiers
Dang, I'm off my game today. Thanks for the correction.
DaveyM69 wrote: As you've already discovered below, also incorrect... the can have any signature and even a return type!
Yeah, I think this is what threw me off:
Finally, even though C# allows it, the .NET framework adds a restriction on the signature of delegates that can be used as events. The signature should be foo(object source, EventArgs e), where source is the object that fired the event and e contains any additional information about the event.
|
|
|
|
|
Friends
I, myself and with the help people of codeproject, developed a windows application.
It is running fine BUT while printing recpt. via crystal report some garbaje is getting print(where varibale data exits).
sometime it doesnt print any data(ie. variable data) and sometime it prints garbage and sometimes it print PERFECT.
Donno why?
PLz Help
|
|
|
|
|
Is Print preview OK? Does other application like Word print normaly?
I think you have a bad connection to printer, Check the cable.
|
|
|
|
|
I am developing a Win CE app in c#,
I need to use a ssl certificate and make calls to the secure(https) web service.
please help how i can add the server certificate (".cer" file) before making calls to the web service.
This is what i am trying.
using System.Net;
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback;
where CertificateValidationCallback will validate an X509 certificate.
But i am not getting ServerCertificateValidationCallback property, as i think its not avilable for device application.
So whats the alternate option to implemennt the same.
Please help!
Thanks in advance,
Fatima
|
|
|
|
|
Hi ppl,
I have a table with two column ID (tinyint) and TEXT (varchar). I am using this table to populate the droplist on my windows form.
when i select items from the droplist I am getting this error "ByteConverter cannot convert from System.Int32." NotSupportedException was unhandled.
I am populating the selected ID of the droplist into the main table.
Pls help.
thanks,
|
|
|
|
|
show us the code that's handling the selection of the droplist item....45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
combobox.datasource = data.tbtest;
combobox.DisplayMember = "Text";
comboBox.ValueMember = "ID";
This code populates the combobox droplist. and the user selects the appropriate value and the selectedvalue ID gets stored into the Form Table on Button click.
Just to add on (on Button Click)
table.TestID = Convert.ToByte(comboBox.Selectedvalue)
I hope this makes sense.
|
|
|
|
|
I'm not clear why you are converting it to a byte, however ...
SelectedValue is of type Object and so you will be calling the Convert.ToByte overload that takes Object , which MUST implement IConvertible . Int32 does not implement this interface.
The solution is to force it to an int first . e.g.
table.TestID = Convert.ToByte((int)comboBox.Selectedvalue)
|
|
|
|
|
|
Thanks, I stand corrected. I checked as far as it is a structure and missed the interface declaration.
|
|
|
|