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 6903897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:58:57+00:00 2026-05-27T07:58:57+00:00

I wrote a function that uses DLL for its purposes. the class where this

  • 0

I wrote a function that uses DLL for its purposes. the class where this function is present has callback for dll for monitoring this function state and a field that I must use in another class.
While I am calling this function in target class I must contineusly get this field value (for progress bar) or pass “Halt” in this callback but it only possible when function finishes execute/
How could I do this?
There is My code. I need to cancel engine via progressbar dialog Cancel

 class LibWrap //containing the LONG process with dll
{
public bool cancelThisBoringProcess;
public int currentPecentage;
public delegate void  pfnCallback(int progress, out bool cancel);
public void showProgress(int progress, out bool cancel)
{
 cancel = cancelThisBoringProcess; 
 currentPecentage = progress;
} 
[DllImport("Lib.DLL", CallingConvention = CallingConvention.Cdecl)]
 public unsafe static extern byte* bufferOp(byte* data,pfnCallback del);
public unsafe  BitmapFrame engine(BitmapFrame incomingFrame)
{
//...
 fixed (byte* inBuf = incoming)
 {
var callback = new pfnCallback(showProgress);
byte* outBuf = bufferOp(inBuf, callback);//this is DLL function with callback to get out percentage //and pass cancel
      GC.KeepAlive(callback);
//....
}
}
}
class Main
{
void OnClick(object sender, RoutedEventArgs e)
{
ProgressDialog dlg = new ProgressDialog("");
LibWrap lwrap = new LibWrap();
DoWorkEventHandler handler = delegate { BitmapFrame bf = lwrap.engine(img)); };

            dlg.AutoIncrementInterval = 100;
            dlg.IsCancellingEnabled = true;
            dlg.Owner = Application.Current.MainWindow;
            dlg.RunWorkerThread(handler);
}
}

//the ProgressDialog is from http://www.hardcodet.net/2008/01/wpf-progress-dialog

  • 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-27T07:58:58+00:00Added an answer on May 27, 2026 at 7:58 am

    I think you mentioned it, but here is the callback pattern:

    void LongOperation(object someParam, Function<int, bool> callback)
    {
          int progress = 0;
          while (progress++<100)
          {
              // lengthy operation:
              Thread.CurrentThread.Sleep(1);
    
              if (!callback(progress)) 
                  break;
          } 
    }
    

    This also shows how a callback can be used to interrupt/cancel the long operation

    bool alwaysCancelAt30Seconds(int progress)
    {
         if ((DateTime.Now - startTime).TotalSeconds <= 30)
         {
              form1.lblProgress.Text = progress.ToString();
         } else
         {
              form1.lblProgress.Text = "canceled due to timeout!";
              return false;     // means 'abort'
         }
         return true;           // means 'continue'
    }
    
      // call site:
      LongOperation(new [] { "some", "data" }, alwaysCancelAt30Seconds);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I wrote this function that uses a binary search to look for a specific
I wrote a program that uses builtin function bin(), but this function is new
I wrote a sample program at http://codepad.org/ko8vVCDF that uses a template function. How do
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
I have this Array i wrote a function MostFreq that takes an array of
I wrote a javascript function that uses the innerHtml of a named div (that
I wrote a nice little array class in C++ that uses void* to save
I wrote a function that uses YQL to pull stock info as follows: function
I have a php function I wrote that will take a text file and

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.