devxlogo

Canceling a call to a dll

Canceling a call to a dll

Question:
In a program, I’m calling a function in a dll. The time before that function is finished can vary from a few seconds to an hour, depending on the start values and how big the problem is.

I want the user to be able to cancel if he/she thinks it takes too long, and perhaps start over with other start values.

I’ve tried to call the dll in a thread, using createThread, and then closing the thread when the user presses the cancel button. But I get strange errors, and I can’t find where they occur.

Is there another way to cancel a call to a dll?Or is there a good example of how to solve it with a thread somewhere?

Answer:
Here’s one way to do it. Declare an event in the DLL with a Boolean parameter. In the long running function, periodically raise the event and check the Boolean parameter to see whether the user canceled it.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist