Hi,
I have some trouble understanding why my code doesnt work the way I want.
Clicking on a button launches a call to a thread for sending mails:
// the delegate to the method sending mails
delegate void mailingEntry();
//button clicked: go to the mail processing....
myMailerDel = new mailingEntry(sendBCCLoop);
myMailerDel.BeginInvoke(null, null);
the fonction sendBCCLoop updates a progress bar while sending mails... As I first have to go back to the UI thread, I dont access to the progress bar from send BCCLoop, instead I do the following:
1. Define another delegate for the method in charge of updating the progress bar.
// If i want to send message to the UI's progressbar, i'll do it using this
delegate void updateIHMMailing(string msg);
myUpdater = new updateIHMMailing(updateEntry);
2. call this second delegate from sendBCCLoop()
this.BeginInvoke(myUpdater, new Object[] { "toto" });
and so we land in the updateEntry function:
private void updateEntry(string msg)
{
if (prgEvoMailing.InvokeRequired == false)
{
prgEvoMailing.PerformStep();
}
else
{
BeginInvoke(myUpdater);
}
}
Doing like this, it WORKS PERFECTLY, no pb.
BUT i want to use the delegate's beginInvoke, not the Form Begin Invoke (ie this.BeginInvoke) ..The code will move to another CS file, for separating UI code from worker thread code... Easyer to read... So i cannot use "this" from the newly created class.
So i thought it would be easy to replace this.BeginInvoke(myUpdater, new Object[] { "toto" }) with myUpdater.beginInvoke(...)...
The pb is that when doing so, everything crashes as long as i try to send a string as parameter:
myUpdater.beginInvoke("toto", null, null) -> Crashes....
BUT if i changes the delegate to take no parameters:
delegate void updateIHMMailing();
private void updateEntry();
And then try again:
myUpdater.beginInvoke(null, null)
Everything is smooth, progress bar responding, code is OK....
so:
Using This.Begininvoe with strings as params -> OK
Using delegate.BeginInvoke WITHOUT params -> OK
Using delegate.BeginInvoke with strings as params -> crashes...
What did i miss
Thanks a lot for your help
Regards
Guillaume RIPOLL

Cannot add parameters to delegate.BeginInvoke : delegates parameters count mismatch
mlord1
private void updateEntry(string msg)
{
if (prgEvoMailing.InvokeRequired == false)
{
prgEvoMailing.PerformStep();
}
else
{
BeginInvoke(myUpdater);
}
}
is a HUGE mistake...
private void updateEntry(string msg)
{
if (prgEvoMailing.InvokeRequired == false)
{
prgEvoMailing.PerformStep();
}
else
{
updateIHMMailing tmpUpdater = new updateIHMMailing(updateEntry);
BeginInvoke(tmpUpdater, new Object[] { msg });
}
}
Sounds better...
Thats is why it was ok using this.beginInvoke i gess, as invoke was never required...
But why was it ok if not using parameters with such a BIG bug
also, what is the use of the "object" parameter, the last one when using BeginInvoke from a delegate.
Thanx
Guillaume RIPOLL