Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:51:19+00:00 2026-05-27T04:51:19+00:00

All, I wish to write a plugin .dll to be used/called by a .NET

  • 0

All,

I wish to write a plugin .dll to be used/called by a .NET application called at runtime. My .dll is a WinForm and displays the (computationally expensive) operations being undertaken. The .dll is called from the main application are invoked via .NET System.Reflection. I have to provide to the calling application the NameSpace, Class and the Method I want to invoke.

I would like to multi-thread my .dll so that it is more UI friendly and I am only really familiar with BackgroundWorkers.

EDIT: Extension to question.

So, I call the .dll as follows:

if (classType != null)
{
    if (bDllIsWinForm)
    {
        classInst = Activator.CreateInstance(classType);
        Form dllWinForm = (Form)classInst;
        dllWinForm.Show();

        // Invoke required method.
        MethodInfo methodInfo = classType.GetMethod(strMethodName);
        if (methodInfo != null)
        {
            object result = null;
            // The method being called in this example is 'XmlExport'.
            result = methodInfo.Invoke(classInst, new object[] { dllParams });
            return result.ToString();
        }
    }
    else
    {
        // Else not a WinForm do simalar.
    }   
}

So then in the WinForm .dll I want to multi-thread the time consuming work so that I can display what is going on. So in the .dll, using BackgroundWorker I have:

BackgroundWorker bgWorker; // Global.    

public string XmlExport(object[] connectionString)
{
    try
    {
        bgWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
        bgWorker.DoWork +=  new DoWorkEventHandler(bgWorker_DoWork);
        bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged);
        bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);

        // Wait until workerThread is done.
        threadDoneEvent = new AutoResetEvent(false);
        bgWorker.RunWorkerAsync();
        threadDoneEvent.WaitOne();
        return strResult; // Global String strResult
    }
    catch (Exception)
    {
        throw;
    }
}

Then I have the DoWork event handler:

void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundWorker thisWorker = sender as BackgroundWorker;
    strResult = (string)this.XmlExportBgw(ref thisWorker); // Or should I use bgWorker?
    e.Result = strResult;
}

public string XmlExportThreaded(ref BackgroundWorker thisWorker) 
{
    try
    {
        // Some expesive work...

        // UI.
        InfoBall infoBall = new InfoBall(); // Class containing processing information.
        // Set infoBall parameters here...
        (thisWorker as BackgroundWorker).ReportProgress(infoBall.progressBarValue, infoBall);

        // Some more expensive work...

        // UI.
        (thisWorker as BackgroundWorker).ReportProgress(infoBall.progressBarValue, infoBall);
    }
    //...
}

The `ProgressChanged’ event is

void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    // UI.
    InfoBall someBall = (InfoBall)e.UserState;

   // Update process information.
   if (someBall.showRichTextBox)
   {
       this.richTextBox.AppendText(someBall.richTextBoxText);
       this.richTextBox.ScrollToCaret();
   }
   return;
}

In addition to the above code I have the usual RunWorkerCompleted etc.

The calling application has been written to allow the user to call thereown .NET .dlls at runtime. The .dll I am trying to put together is a time intensive one and one that will only be supplied to particular users. I have run the above code and the problem is that it will not update the user interface correctly. That is that you cannot manipulate (resize, click etc.) the Form and it does not print and progress information until the very end of the processing when it only prints the final message out multiple times. However, it is correctly producing the .xml files I require. What am I doing wrong? Should I be invoking the .dll method from a separate thread?

Any help would be greatly appreciated. Thanks very much for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:51:19+00:00Added an answer on May 27, 2026 at 4:51 am

    I am not sure what kind of methods you are tryng to execute in that dll. I am assuming they are not asynchronous meaning your main thread (application) will stop until they are done executing. An easy example could be demonstrated with the Messagebox.show(“myMessage”); method. For example how could you execute 3 message boxes at once? it will not be possible without using multiple threads. Hope this methods helps:

        public void SomeMethod()
        {
    
    
            Thread thread = new Thread(new ThreadStart(() =>
            {
                // this code is going to be executed in a separate thread
                MessageBox.Show("hello");    
    
                // place additional code that you need to be executed on a separate thread in here            
    
            }));
    
            thread.Start();
        }
    

    then if I call that method 3 times as:

    enter image description here

    I will now be running 4 threads on my program. The main thread plus the 3 calls that I created.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to get a list of all strings that are used in a
I wish to implement a fairly simple CSV checker in my C#/ASP.NET application -
I wish to develop an application in VB.NET to provide to following functionality and
All I wish to call the svnlook commandline from my MSbuild script using the
How you doing today? Wish you all good. By the way, here is my
I wish to know all the pros and cons about using these two methods.
I wish to find all rows in a table where one column is a
I wish to get the number of all TR elements that have a input
I have a load of signatures I wish to compare (all in ISF -
Given the following list of descending unique numbers (3,2,1) I wish to generate all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.