> Hi everyone.
>
[quoted text clipped - 33 lines]
> Thanks,
> /Aidal
I've switched away from the User Control and I'm now using a normal Windows
Form instead to try and anrrow down the possible error sources.
The issue is still the same though :(
Where are some an example of what I'm trying to do:
------------------------------------------------------------
// InitializeExBgw() is called in the form constructor.
private void InitializeExBgw()
{
this.ExBgw = new ExtendedBackgroundWorker();
this.ExBgw.DoWork += new DoWorkEventHandler(ExBgw_DoWork);
this.ExBgw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(ExBgw_RunWorkerCompleted);
}
private void ExBgw_DoWork(object sender, DoWorkEventArgs e)
{
ExtendedBackgroundWorker worker = sender as
ExtendedBackgroundWorker;
SQLServerLocator locator = new SQLServerLocator(); // My own
class. Scans for SQL servers on the network.
string[] servers = locator.GetServers();
e.Result = (string[])alTemp.ToArray(typeof(string));
}
private void ExBgw_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
string[] servers = new string[] { "" };
if (e.Error != null)
{
MessageBox.Show(this.Init.GetLanguageMessageError(2, "\n\n",
e.Error.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (e.Cancelled)
{
}
else
{
if (e.Result != null)
{
servers = (string[])e.Result;
// this part will produce the cross-thread error
foreach(string s in servers)
{
this.ComboBox1.Items.Add(s);
}
}
}
// this however, does not produce the cross-thread error
this.PictureBox1.Image = null;
}
private void btn_Search_SQLServers_Click(object sender, EventArgs e)
{
this.PictureBox1.Image = "my_progress_gif_file.gif";
this.ExBgw.RunWorkerAsync(null); // used to send an object with
it, but it's not used in this example, hence "null".
}
------------------------------------------------------
Why can I load an image into a PictureBox but not populate a ComboBox or set
the Text property on a Label for that matter in "ExBgw_RunWorkerCompleted" ???
This doesn't make sense to me...
/Aidal
> Oh by the way, I don't know if this changes things at all but I forgot to
> mention that what I'm doing is not in an Outlook form but in a User Control
[quoted text clipped - 39 lines]
> > Thanks,
> > /Aidal
Aidal - 21 Jul 2007 21:21 GMT
Seriously, nobody knows how to do this in Outlook or a simple windows
form in an add-in?
> I've switched away from the User Control and I'm now using a normal Windows
> Form instead to try and anrrow down the possible error sources.
[quoted text clipped - 117 lines]
>>> Thanks,
>>> /Aidal
Ken Slovak - [MVP - Outlook] - 23 Jul 2007 14:42 GMT
I don't think there's a lot of expertise here in working with background
threads.
I'd suggest taking a look at Outlook MVP Jay Harlow's Web site and sample
for using a background worker thread at
http://www.tsbradley.net/Samples/VSTO/Xml.Export.Sample.aspx and reviewing
his work with background worker threads and see if that gives you any clues.
His example is written using VB.NET and VSTO 2 so you will need an
installation of Outlook 2003 and a compatible setup of VS to open the
project or you can just unpack the zip and port the code modules into a
compatible setup you have.

Signature
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
> Seriously, nobody knows how to do this in Outlook or a simple windows form
> in an add-in?
[quoted text clipped - 123 lines]
>>>> Thanks,
>>>> /Aidal