|
Fianlly i got answer by invoking the label
public void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
this.label1.Invoke(
(MethodInvoker)delegate()
{
label1.Text = Convert.ToString(DateTime.Now);
}
);
}
|
|
|
|
|
As Andrei has stated above, the rule is that only the thread which creates a control should update it.
You could alternatively use the System.Windows.Forms timer, as this always fires on the primary GUI thread and no thread switch is required.
Regards,
Rob Philpott.
|
|
|
|
|
Finally i got the answer by invoking the Label. Thank u
public void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
this.label1.Invoke(
(MethodInvoker)delegate()
{
label1.Text = Convert.ToString(DateTime.Now);
}
);
}
|
|
|
|
|
I have this application that sends mail to a mail server.The server uses Domino Lotus iNote to distribute and display the mails.But when a user receives the mail,the column that suppose to show the "Who" is always blank/empty making the mail look more like a spam.And some users don't care to open it thinking that it is a spam.
Can anyone help me out with how to fill this "Who" column.
I use:
MailMessage myMail = new MailMessage();
myMail.From = "myname@me.com";
myMail.To = "emailTxt.Text";
myMail.Fields.Add("SenderName","myname");
myMail.Subject = "You Have Been Appraised!";
myMail.BodyFormat = MailFormat.Text;
myMail.Body = "Go and confirm or contest your mail! ";
SmtpMail.SmtpServer = "10.12.19.105";
SmtpMail.Send(myMail);
I don't know if there is another parameter that is required to be able to send an email to domino lotus iNote.
|
|
|
|
|
Hi I need to get the Focused Property of My ListBox list from within a thread. The thread makes calls to following function
<br />
bool listFocused()<br />
{<br />
if (this.list.InvokeRequired)<br />
{<br />
ListFocusCallBack d = new ListFocusCallBack(listFocused);<br />
Object obj = this.list.Invoke(d, new object[] {});<br />
}<br />
else<br />
{<br />
return this.list.Focused;<br />
}<br />
}<br />
If I compile the above then I get a "not all code paths return a value" error, because I'm not returning anything in "ProblemLine"
I tried replacing "ProblemLine" with
if( obj.Equals(Boolean.TrueString ))<br />
return true;<br />
return false;<br />
but I'm not sure if it is the right approach.
Please Advice
Thanks...
|
|
|
|
|
Hello,
You don't need the else statement in your method.
If invoke is called the code after that will not been worked threw.
Set a breakpoint at the first line of the method and Debug it to see it better.
Your method could look like that:
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
this.list.Invoke(d, new object[] {});
}
return this.list.Focused;
}
-- modified at 8:07 Wednesday 21st November, 2007
Wrong Information Sorry
All the best,
Martin
|
|
|
|
|
To my knowledge, it's not thread safe this way, let me explain :
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
this.list.Invoke(d, new object[] {});
}
return this.list.Focused;
}
what you need to do is to return value that Control.Invoke method returns
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
return (bool)this.list.Invoke(d, new object[] {});
}
else
{
return this.list.Focused;
}
}
zilo
|
|
|
|
|
Hello Zilo,
I do not agree with you.
Zilo(svk) wrote: return this.list.Focused; // !!! again [T1] - if u invoke a delegate using control invoke, it doesn't mean // that the rest of this method will be executed on that invoked thread. it // remains on thread [T1], where it's not safe to get the Focused value.
This code will never be executed by [T1] AFAIK.
After the Invoke call, the method will no longer go threw the rest of the method code.
I often debugged such a situation, and hope what I just told is not complete rubbish!
-- modified at 8:09 Wednesday 21st November, 2007
I wrote: hope what I just told is not complete rubbish
It was rubbish!
All the best,
Martin
|
|
|
|
|
Test it. It really is the way I wrote. I mean I don't see any reason why Control.Invoke(delegate Method); should for any reason make calling method to return whatever the delegate returns. It does just doesn't make any sense. Execution continues. It just blocks until delegate completed.
zilo
|
|
|
|
|
Hello Zilo,
Just testet it, and have to say THANK YOU SO MUCH for pointing that out.
First of all, I was not consistend in my Projects.
And second, I was completely wrong.
Thats what I like at CP.
By answering (or trying to do so at least), you also get support!
Got my '5'.
Thanks again!
All the best,
Martin
|
|
|
|
|
np,
It's good to know that you know something ) . I wasn't sure either about this one.
zilo
|
|
|
|
|
I was also thinking on similar lines what I actually did was
<br />
if (this.list.InvokeRequired)<br />
{<br />
ListFocusCallBack d = new ListFocusCallBack(listFocused);<br />
Object obj = this.list.Invoke(d, new object[] {});<br />
<br />
if( obj.Equals(Boolean.TrueString ))<br />
return true;<br />
return false;<br />
}<br />
else<br />
{<br />
return this.list.Focused;<br />
}<br />
Your solution about converting Object to bool as (bool)obj never came to my mind. I never knew it was possible.
Thanks...
The Show Ain't Over Yet...
|
|
|
|
|
it send data to tcp/ip port number, ex 8080, now i want to write socket program to read data from that port. Any body help me? How can i do that?
plz post the code
|
|
|
|
|
No more comment!
All the best,
Martin
|
|
|
|
|
Couldn't agree more....
Standards are great! Everybody should have one!
|
|
|
|
|
Try here [^]. You will surely get the kind of help you want.
I will use Google before asking dumb questions
|
|
|
|
|
I'm doing this just to prevent you from posting continuous new threads on this forum. Use this [link] . It an old post of mine to another problem, there you have a code sample to get you started. And next time search CodeProject and Google, get you hands dirty and when you're stuck come here and post question; if you want code use the link I gave you earlier.
I will use Google before asking dumb questions
|
|
|
|
|
I'm sorry, but which bit of we aren't here to do your job for you is so hard to understand? If you can't cope with a task like this, with the advice you've already been given, then I would consider a career change to one where the only questions you need to ask is
"Do you want fries with that?"
|
|
|
|
|
Pete O`Hanlon wrote: f you can't cope with a task like this, with the advice you've already been given, then I would consider a career change to one where the only questions you need to ask is
"Do you want fries with that?"
Nice one.
I will use Google before asking dumb questions
|
|
|
|
|
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
|
Hello
I'm stuck with a C++ (or something) Dll that i'm supposed to call from a c# App.
(or even "better" from a vb.net app )
The header file says something like
int Initialize([in]unsigned int SlotID, [in]unsigned char* Label, [in]unsigned char* Pin, [in/out]void* hSession);
this
[DllImport("MyDll.dll",EntryPoint="Initialize", ExactSpelling=true, SetLastError=true)]
private extern static void Init(uint SlotID, string Label, string Pin, out IntPtr Handle);
doesn't work at all. it tells me that the target caused an error.
now i tried to marshal the types like
[DllImport("MyDll.dll",EntryPoint="Initialize", ExactSpelling=true, SetLastError=true)]
private extern static void Init([MarshalAs(UnmanagedType.U4)]uint SlotID, [MarshalAs(UnmanagedType.LPStr)]string Label, [MarshalAs(UnmanagedType.LPStr)]string Pin, out IntPtr Handle);
this gives me an Access Violation and marshalling the strings as LPTStr isn't any better.
my last try to build a fixedString struct for passing to that method
[StructLayout(LayoutKind.Sequential)]
private struct fixedString
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=23)]
string MyString;
}
[DllImport("MyDll.dll",EntryPoint="Initialize", ExactSpelling=true, SetLastError=true)]
private extern static void Init([MarshalAs(UnmanagedType.U4)]uint SlotID, fixedString Label, fixedString Pin, out IntPtr Handle);
well you know... *sigh*
i even tried to make it work with unsave coding but still got access-violations or just with that TargetInvocationException
does anybody have an idea how i could get that thing to work?
thanks in advance
greets
m@u
|
|
|
|
|
If any strings get changed in the unmanaged code you have to use a StringBuilder object.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Thank you. i'll test that as soon as i can
this marshalling thing still confuses me a bit. do i have to tell the clr how to marshal the stringbuilder, or should it work when i leave all the marshalAs attributes away?
m@u
|
|
|
|
|
Hi,
Is the fact that your method return types are different, int vs. void, relevant or is that just a typo in the post.
Alan.
|
|
|
|