The VC DLL time slice refresh thread

Updated on healthy 2024-02-09
14 answers
  1. Anonymous users2024-02-05

    This is an out-of-sync issue between threads.

    You add an afxmessagebox, which is equivalent to adding a waiting time, and in the process of waiting, the system processes the ondatachange message and runs the ondatachange() function.

    Method 1: If you use POST when you send a message that triggers the ondatachange event, you should use SendMessage

    Method 2: You can also add a sleep(30) to the messagebox, but that's not a good practice.

    Method 3: If you encounter a similar problem, you can also use cmutex to control access to a certain variable, you will understand it after learning multi-threaded programming.

    You just use method 2, sleep(30) or sleep(50),At most, it can't exceed 100, and the rest is difficult to tell you clearly.,Go find this book about win32 api programming.。

    You send the ** over, I'll help you deserve.

  2. Anonymous users2024-02-04

    I'm the one who asked the question. One more question: there is some connection to the question above.

    carraym_data10array;

    int idata;Initialize to 0

    The resulting value is then added to the collection class in an ondatachenge event (assuming the function is called 500 times).

    csdata is of type cstring.

    m_;After the function is called, I call the func function to read the data in the collection class, (which will also be called 500 times).

    int func(double* pvalue)

    int i;

    cstring str;

    i = m_;

    There are %d records in the collection class, now look for %d", i, idata);

    afxmessagebox(str);

    pvalue = m_;

    idata++;

    return 1;

    That's the idea, but something went wrong. The first time the func function is called, i = m; Why is there a 0 value in the resulting collection class? Then running to m crashes the program (an unusual dialog pops up).

    But if I click the "Ignore" button on the exception dialog, the program comes alive again, and the pvalue returned for the first time is the correct value. Why is that?

    The main problem is, i = m; How can i be 0?

    Hurry, hurry.

  3. Anonymous users2024-02-03

    If it's in the same thread, you can solve it with sendmessage (ondatachange I don't know if it's a message raised by itself?). )

    Another way to do this is to get the value in the same way as message, because the message queue is queued, and you add such a function to the header file.

    lresult msgtogetvalue(wparam,lparam)

    Add message mapping.

    onmessage(wm user+123,msgtogetvalue) wm user+123 can be replaced at will.

    cpp file, lresult msgtogetvalue(wparam, lparam).

    return All variables;

    In fun2, change the return global variable to:

    int ret = ::sendmessage(wm_user+123,0,0);

    return ret;

    That's it, get the global variables in ondatachange.

  4. Anonymous users2024-02-02

    Let's see if you can use sleep (delay in milliseconds). See if you can put func2 messages into the message queue.

  5. Anonymous users2024-02-01

    Do not create threads in dllmain, as the ** in dllmain will be executed repeatedly.

    You can use a separate function to start a thread, and here is a dll I wrote that makes the PC speaker ring every 1 second, you can refer to it.

    Global variables. bool api_nthreadflag = true;Thread run flag.

    dword __stdcall thread(lpvoid wparam);

    bool apientry dllmain( handle hmodule,dword ul_reason_for_call,lpvoid lpreserved

    return true;

    _declspec(dllexport) void winapi startthread()

    declspec(dllexport) void winapi endthread()

    dword __stdcall thread(lpvoid wparam)

    return 0;}

  6. Anonymous users2024-01-31

    Microsoft has said that don't create thread ...... in dllmain

  7. Anonymous users2024-01-30

    The handles returned by BeginThreadEx and CreateThread are saved, and the creation time of the thread can be obtained by using the getthreadtimes function, and it will come out as soon as it is subtracted, notifying the end of the sub-thread or using terminatethread to force the end.

    The control mechanism must be written by yourself, and the library that comes with VC does not encapsulate this functionality.

  8. Anonymous users2024-01-29

    You add sleep to a sub-thread to slow things down.

    To trigger exactly, use gettickcount()Whether the difference between the last time and the current time is greater than the fixed time interval is determined.

  9. Anonymous users2024-01-28

    It's a matter of priority. Higher priority gets more time slices.

    The tasks in the background are basically the so-called background segment spine priority, and the system can set whether to prioritize the background or the foreground, and generally give priority to the foreground, and the things in the background will not have any impact on the performance of the foreground. There are also more generous programs that are the Idle priority, which means that they are only in a daze when the system is in a daze, and it will not affect your ability to do things normally.

    But in any case, the problem of time sharding is inevitable, and if you want to determine the time more accurately or the running time of certain statements, etc., it is a matter of hand destruction.

  10. Anonymous users2024-01-27

    1. The process is prioritized, I don't know the thread. However, the priority will definitely affect your program, because the PC does not have the Kai is the real talk about the Kai Rushi operating system, but the multitasking system Sun Qi.

  11. Anonymous users2024-01-26

    It is not possible to define oneself by oneself, this is determined by the operating system.

    However, the program can set a priority for each of its threads, and the priority will affect the length of the thread's time slice.

  12. Anonymous users2024-01-25

    The thread on which the function is called, runs on that thread.

    It has nothing to do with the thread that created the object.

  13. Anonymous users2024-01-24

    You can inject ** into the target process and then call getmodulehandleex

    Or use toolhelp to directly iterate through all the dlls of the specified process

  14. Anonymous users2024-01-23

    Too lazy to type, just hang the net (don't blame me, it's really annoying.) The modifier name of the export function, declspec(dllexport),def file, not in a word) public declare function yourfuncwithoutdecorate lib"" (byval yourarg as yourclass) as string。

Related questions
18 answers2024-02-09

The most widely accepted physical theory of time is Albert Einstein's theory of relativity. In the theory of relativity, time and space, together form a four-dimensional space-time, which constitutes the basic structure of the universe. Time and space are not Einstein's absolute, and the passage of time measured by observers at different relative velocities or at different measurement points of different space-time structures. >>>More

7 answers2024-02-09

At one point, scientists studied the possibility of transcending the speed of light, fantasizing about one day being able to build rockets that move faster than the speed of light. In this way, people can catch up with the light signals emitted on the earth by simply riding this rocket and thus see what happened on the earth in the past. This means that at the speed of light, time will be reversed, and people will pass tomorrow, today, and then yesterday. >>>More

15 answers2024-02-09

Strip. Hurt Zhongyong.

Wound Zhongyong is an essay written by the Northern Song Dynasty writer Wang Anshi. tells the story of a prodigy named "Fang Zhongyong" from Jinxi, Jiangxi Province, who was reduced to an ordinary person because his father did not let him study and was used by his father as a money-making tool. Taking Zhongyong as an example, the article warns people that they must not simply rely on aptitude without learning new knowledge, but must pay attention to acquired education and learning, emphasizing the importance of acquired education and learning for becoming talents. >>>More

5 answers2024-02-09

The three watches are lit up and the five watches are when the boys are studying. >>>More

5 answers2024-02-09

1. Tomorrow after tomorrow, tomorrow is so much!

2. If the young man does not work hard, the boss will be sad. >>>More