SampleDataInstallerClass -> cross-thread error...


Author
Message
Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Hi there,

maybe I'm doing something stupid, but I tried the SampleDataInstallerClass from the Example.zip for C#. I unpacked the examples to the projects directory and opened the solution with VS2005. Then I corrected the references to my new strataframe components on my machine and started debugging.

I tried the Pre-Build Dialogs, but as soon as I click on the combobox to choose the server, I get an exception in MDDeployMain.vb at

 '-- Clear the combo

cboSQLServer.Items.Clear()

telling me, there is a cross-thread call exeption.

Therefore I can't choose any server and have to stop debugging.

Any hint?

TIA and friendly greetings, Ralph

StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Could you show the code where you are creating and showing the MDDeployMain form? 

Are you calling .Show() on the form or .ShowDialog() on the form?

Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Hi Ben,

"I unpacked the examples to the projects directory and opened the solution with VS2005. Then I corrected the references to my new strataframe components on my machine and started debugging."

I used the CSharpDemos.exe examples from Microfour for StrataFrame - http://forum.strataframe.net/Topic5397-17-1.aspx without any changes other than to correct the references.

Can you reproduce the error with the example like it is?

TIA and friendly greetings, Ralph

Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Ralph,

I ran the C# sample that gets installed with the framework (instead of the one from the forum) and did not have any issues.  The one from the forum was ultimately added to the install.  Click Start -> StrataFrame -> Samples -> C# -> Database Installer Sample.  Run this sample to see if you have the same issue.  I am not having any issues with the sample.  If you are running the installer class (not the standard part of the sample) through an installation, then you have to take this into account if you are executing the install on another thread by creating a delegate or a synchronization object (ISynchronizeInvoke).  But if you are just running the WinForms sample, then I cannot reproduce.  Any additional details would be helpful Smile

Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Hello Trent,

> I ran the C# sample that gets installed with the framework (instead of the one from the forum) and did not have any issues.  The one from the forum was ultimately added to the install.  Click Start -> StrataFrame -> Samples -> C# -> Database Installer Sample.  Run this sample to see if you have the same issue. <

Yes, I do. Unfortunately. I did exactly what you described:

I clicked on 'Pre-Build Dialogs', then 'Next' without touching anything else, after that I clicked on the little down arrow at the combobox for selecting an SQL Server.

At this point I get the following error message:

 'System.InvalidOperationException was unhandled by user code
  Message="Ungültiger threadübergreifender Vorgang: Der Zugriff auf das Steuerelement cboSQLServer erfolgte von einem anderen Thread als dem Thread, für den es erstellt wurde."
  Source="System.Windows.Forms"
  StackTrace:
       bei System.Windows.Forms.Control.get_Handle()
       bei System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, Int32 lparam)
       bei System.Windows.Forms.ComboBox.NativeClear()
       bei System.Windows.Forms.ComboBox.ObjectCollection.ClearInternal()
       bei System.Windows.Forms.ComboBox.ObjectCollection.Clear()
       bei MicroFour.StrataFrame.DBEngine.Deployment.MDDeployMain.LoadSQLServers()
       bei MicroFour.StrataFrame.DBEngine.Deployment.MDDeployMain.sqlWorker_DoWork(Object sender, DoWorkEventArgs e)
       bei System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       bei System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

Maybe there is something wrong with my machine?

TIA and friendly greetings,

Ralph


 

Attachments
SampleDataInstallerClassError.jpg (203 views, 100.00 KB)
Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Maybe there is something wrong with my machine?

It is funny that you mentioned this....you are getting a cross-thread violation, which we have run into an issue recently where one machine would get the error and not another.  The difference had to do with AMD dual cores and another machine with an Intel HyperThreading procesor.  Strange, but true.  I wonder if there is something along these lines going on here.  I will look to see if there is some other precaution that we could take to aid in preventing this.  Thanks for the info.

Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Hi Trent,

my machine is equipped with an AMD Athlon 64X2 Dual Core Processor 4200+ / 2,21GHz, 1,00 GB Ram.

Unfortunately I can't run a test against a machine equipped with Intel chipset and processor because I do not have one near around. Are you using Intel without that problem? Then my next machine will surely have Intel on board.

Thank you very much and friendly greetings,

Ralph

Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Actually I am using an AMD X2 Dual Core 6400+ ... I will still look into the issue to see if there is something that can be done.  Thanks.
Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Hello Trent! Smile

Meanwhile I kicked off my old AMD equipment and own a brand new Intel machine now. BigGrin

I installed all completly new from the scratch, Windows XP Professional, VS 2008 and the newest StrataFrame-Beta.

Unfortunately the problem persists, even with the new machine. It seems not to have something to do with AMD or Intel.

So I took a look what MicroSoft does with the Backgroundworker, which should have something to do with the error. I saw, that the examples from MS avoid any access to the GUI, from inside the doWork-Method. I tried to modify the source code, but found that not a good idea, because I do not want to modify the code again and again with any new release of SF.

I decided to translate the DeployDialogs-MDDDeployMain to C# and to modify it to my needs, using as much of the framework as I could.

And guess what? Right, the problem went away! BigGrin

Here is, what I did (among others):

private void cboSQLServer_DropDown(object sender, EventArgs e)

{

if (!_ServersLoaded)

{

_ServersLoaded = true;

//-- Clear the combo

this.cboSQLServer.Items.Clear();

//-- Start the thread

this.sqlWorker.RunWorkerAsync();

}

}

private void sqlWorker_DoWork(object sender, DoWorkEventArgs e)

{

// Do not access the form's BackgroundWorker reference directly.

// Instead, use the reference provided by the sender parameter.

BackgroundWorker bw = sender as BackgroundWorker;

// Start the time-consuming operation.

// e.Result = TimeConsumingOperation(bw, arg);

this.LoadSQLServers(bw, e);

// If the operation was canceled by the user,

// set the DoWorkEventArgs.Cancel property to true.

if (bw.CancellationPending)

{

e.Cancel = true;

}

}

/// <summary>

/// Loads the available SQL servers into the combo box

/// </summary>

/// <remarks></remarks>

private void LoadSQLServers(BackgroundWorker bw, DoWorkEventArgs e)

{

//-- Show the wait window

bw.ReportProgress(1);

//-- Establish Locals

SQLServerSchema loSQL = new SQLServerSchema();

ArrayList list = new ArrayList();

//-- Cycle through all available servers

foreach (SQLServerInfo loSQLInfo in loSQL.LoadSQLServerList())

{

//-- Add the item

list.Add(loSQLInfo.Name);

}

e.Result = list;

}

private void sqlWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)

{

if (e.ProgressPercentage == 1)

{

this.opgWindows.Enabled = false;

this.opgSQL.Enabled = false;

this.cmdBack.Enabled = false;

this.cmdNext.Enabled = false;

//-- this.cmdCancel.Enabled = false;

this.myWaitwindow.ShowWaitWindow(Localization.RetrieveTextValue("waitWindTxt030"), Localization.RetrieveTextValue("waitWindTxt040"));

}

}

private void sqlWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

{

if (e.Cancelled)

{

this.myWaitwindow.HideWaitWindow();

// The user canceled the operation.

MessageBox.Show("Operation was canceled");

this._ServersLoaded = false;

this.opgWindows.Enabled = true;

this.opgSQL.Enabled = true;

this.cmdBack.Enabled = true;

this.cmdNext.Enabled = true;

this.cmdCancel.Enabled = true;

}

else if (e.Error != null)

{

// There was an error during the operation.

string msg = String.Format("An error occurred: {0}", e.Error.Message);

MessageBox.Show(msg);

}

else

{

// The operation completed normally.

ArrayList servers = (ArrayList)e.Result;

for (int i = 0; i < servers.Count; i++)

{

this.cboSQLServer.Items.Add(servers.ToArray().GetValue(i));

}

if (this.cboSQLServer.Items.Count > 0)

{

//-- Select the first item

this.cboSQLServer.SelectedIndex = 0;

}

this.myWaitwindow.HideWaitWindow();

this.opgWindows.Enabled = false;

this.opgSQL.Enabled = false;

this.cmdBack.Enabled = true;

this.cmdNext.Enabled = true;

//-- this.cmdCancel.Enabled = true;

}

}

private void cmdCancel_Click(object sender, EventArgs e)

{

if (this.sqlWorker.IsBusy)

{

// Cancel the asynchronous operation.

this.sqlWorker.CancelAsync();

this.cmdCancel.Enabled = false;

}

else

{

try

{

if (_Migrator != null)

{

_Migrator.CancelConversionThread();

_Migrator.Dispose();

}

}

catch (Exception)

{

throw;

}

finally

{

this.DialogResult = DialogResult.Abort;

this.Close();

}

}

}

Maybe you can have a look at it and use it for the framework? OK, you will have to translate it to VB.NET, but this will surely not be a problem for you and this way you can shift my code to a much better one. Smile

Friendly greetings,

Ralph

Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I am glad that you got it working.  I am unsure why your environment would act differently.  I looked through the code to ensure that there was no cross-thread violations...and I did not see any.  However, we are about to rework this dialog anyway, so I will be sure to take this into account!

Thanks for your information and efforts!!!!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search