-1

I have a dll file which I use elsewhere, but in the dll file, I have a class which needs to be updated very frequently by a function inside it. Then I wanted to just create a loop that executes the function every pass. But even so, it pauses the thread which uses the dll, because it is caught in the loop(waiting for it to be over). So therefore, my program freezes.

So, how can I create this loop without freezing my thread.

PS. I have though and tried to use a Timer(.net), but I really want to exclude managed code.

Bart
  • 19,692
  • 7
  • 68
  • 77
Miguel P
  • 1,262
  • 6
  • 23
  • 48
  • 5
    Can't you just fire up another thread and call the function from that? – learnvst Aug 06 '12 at 20:06
  • No, i want a dll(there is a reason, but i don't want to discuss that now), and i tried to create a timer, but when defining the event handler, i have to mix managed and unmanaged code, builded perfectly, but when debugging, crash. – Miguel P Aug 06 '12 at 20:15

1 Answers1

0

Well without any code samples it won't be easy to give you an exact answer, but basically you need a new thread for this. The way you create a new thread is up to you / the APIs you are using. You could use .NET, you could use boost, as Lirik suggested, WINAPI, whatever. It all boils down to this: Threads in C++ are platform-specific (see Simple example of threading in C++). So without more details about the OS and compiler a working code example won't really be possible. Since the "execution pause" is probably just an infinite loop, you might want to consider reading some material on threading in C++ to begin with.

It's great if the functionality is already encapsulated in a class, because you can give the responsibility of starting and ending the thread correctly to the class itself, without the calling thread knowing anything about it.

Community
  • 1
  • 1
Excelcius
  • 1,680
  • 1
  • 14
  • 31