logo WinWrap®

Cross Thread

WinWrap® Basic is an embedded language control available for .NET/COM 32/64 bit Windows applications. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

Edit, debug and execute scripts in a different thread.


  • Non-blocking script execution.
  • Edit, debug and execute from a BasicIdeCtl control.

Cross Thread

Cross Thread

With a BasicIdeCtl placed on a form, create a BasicThread object containing a BasicNoUIObj object.

public partial class Form1 : Form { // create a thread containing a BasicNoUIObj private BasicThread basic_thread_ = new BasicThread(); ... }

Configure the BasicNoUIObj object and connect it to the BasicIdeCtl control using the Synchronize method and the Synchronizing event and set the SynchronizedEdit property for both:

private void Form1_Load(object sender, EventArgs e) { // get the IDE's synchronization context SynchronizationContext ui_sc = SynchronizationContext.Current; // send an action to the BasicThread basic_thread_.SendAction(basic => { // configure basic basic.Synchronizing += (sender2, e2) => { // response/notification from the remote BasicNoUIObj ui_sc.Post(state => { // send response to the local BasicIdeCtl basicIdeCtl1.Synchronize(e2.Param, 0); }, null); }; // set the BasicNoUIObj's secret basic.Secret = new Guid("00000000-0000-0000-0000-000000000000"); // initialize basic in the remote thread basic.Initialize(); // turn on NoUI's synchronized edit basic.SynchronizedEdit = true; }); // turn on IDE's synchronized edit basicIdeCtl1.SynchronizedEdit = true; }

Connect the BasicIdeCtl control to the BasicNoUIObj object using the Synchronize method and the Synchronizing event:

private void basicIdeCtl1_Synchronizing(object sender, SynchronizingEventArgs e) { // send command to the BasicNoUIObj basic_thread_?.PostAction(basic => basic.Synchronize(e.Param, 0)); }

Wait for the BasicThread to stop and clean things up.

private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (basic_thread_ != null) { if (basic_thread_.Kill()) { basic_thread_.Dispose(); basic_thread_ = null; } else e.Cancel = true; } }

That's it. Now you can edit, debug and execute WinWrap® Basic scripts in a different thread.

Sample source code available.

  • Run sample application from Visual Studio.
  • Application editing, debugging and executing scripts in a different thread.

Client/Server Solutions:

Cross Thread


Web Server

Web Page Client

Copyright Polar Engineering, Inc.