|
As already suggest, you should use a worker thread. Have a look at the classic J.M.Newcomer's article: "Using Worker Threads".
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I would not recommend multi-threading. Don't go there, it won't do you any good. If you need to perform several tasks at once, you are MUCH better off using "idle time processing" using CWinApp::OnIdle() and calling Continue() in the worker object where you perform one little piece of work each time, using a state variable or similar.
Multi-threading should be avoided at all costs. It's hopeless to debug, a maintenance nightmare and you get absolutely no performance benefits from it, except in very special cases (number crunching on a multi CPU, low-level drivers or things like that). Do not use multi-threading, I cannot stress this enough. I speak from bitter experience
|
|
|
|
|
Mattias G wrote: Multi-threading should be avoided at all costs. It's hopeless to debug, a maintenance nightmare and you get absolutely no performance benefits from it, except in very special cases (number crunching on a multi CPU, low-level drivers or things like that). Do not use multi-threading, I cannot stress this enough. I speak from bitter experience Smile
Quote Selected Text
I don't agree at all... Mutli-thread can't be avoided in some cases. Of course, you shouldn't overuse it but there are a lot of cases where it simply can't be avoided.
I agree that this is something hard to learn and difficult to debug but it is sometimes necessary. If it was that bad, why would it be so widely used ?
|
|
|
|
|
Could you provide an example of where multi-threading is a good idea? Would be interesting to hear from someone with good experiences from threads ...
|
|
|
|
|
There are a lot of cases where multi-threading is an advantage.
For instance, when you have a server (probably even without a UI) that should accept different clients at the same time. I can't imagine doing something like that without mutli-threading.
Another example: if you have an application which has to execute tasks (which can be a lenghty operation) and you don't want to freeze the UI. Of course, you could use the OnIdle but this becomes quickly difficult to manage. It is much easier to have a queue object in which you can enqueue the tasks when needed and the queue object processes these tasks in a separat thread, independantly of the UI.
Of course, there are much more examples than that.
|
|
|
|
|
The simplest case would be where you have to wait on a port for data, or you've to wait for an operation to complete, or you have to do a lengthy processing, while still having to keep the GUI responsive.
"Avoid multithreading at all costs" is probably the worst advice I've ever seen here.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Have a look at Idle Loop Processing, namely:
Many applications perform lengthy processing "in the background." Sometimes performance considerations dictate using multithreading for such work. Threads involve extra development overhead, so they are not recommended for simple tasks like the idle-time work that MFC does in the OnIdle function. This article focuses on idle processing. For more information about multithreading, see Multithreading Topics.
Some kinds of background processing are appropriately done during intervals that the user is not otherwise interacting with the application. In an application developed for the Microsoft Windows operating system, an application can perform idle-time processing by splitting a lengthy process into many small fragments. After processing each fragment, the application yields execution control to Windows using a PeekMessage loop.
Aside of performance considerations, I've underlined the key concept behind idle time processing: you need to fragment a lenghty operation. That means you've to build a state machine. Of course it is a viable approach but using a separate thread means that, conceptually, the execution flow is never broken.
Multithreading requires care, I admit, but you cannot deduce by your bad experience with, that multithreading is bad.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
(Late reply, but anyways) Ok, multi-threading isn't always bad It's just that I have seen very few examples where multi-threading brings any real benefits -- a server app as mentioned above might be one, a device driver might be another. On the other hand, I've seen a few extremly tricky maintenance and debugging problems due to MT. For starters, it can be almost impossible just to reproduce a certain behaviour or error in a application with multiple threads. I would probably prefer a state machine in 9 out 10 cases.
/M
|
|
|
|
|
State machines are good. But, for many programmers counter-intuitive.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Mattias G wrote: Multi-threading should be avoided at all costs.
Mattias G wrote: Do not use multi-threading, I cannot stress this enough.
Mattias G wrote: I speak from bitter experience
No, you are speaking from Bitter [^] experience...
sorry for that, it was...irresistible to me
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
Please help me choose how (an API, component, library etc) can I work with POP3 in the following task. I have no experience with POP3 and do not know where to start.
I have C++ Win32-application (MS Visual C++ 2005 or 2008) that must:
- periodically (say once in 5 min) check a mailbox via POP3
- retrieve new messages from there, process them (the processing is specific for the my task) and remove the processed messages.
The question is: what (an API, component, library etc) should be used for this task? Most probably there will be several solutions - if so, please recommend better one.
If, say, there is a ready component that resolves the task, but it is implemented on .Net - how easy to integrate it with C++ application?
Thanx
|
|
|
|
|
POP3 has several commands that are used to retrieve mails, delete mails etc. from a POP3 server.
In Windows you can use sockets to connect to a POP3 server using its IP address and port. (The default port for POP3 is 110).
After this it is just a matter of sending commands and receiving the response.
Read about the POP3 commands and the protocol here - RFC1939 - Post Office Protocol - Version 3[^]
|
|
|
|
|
Thanx. But I also wanted to know - is there some component that implements basic functionality for this task - to avoid writing 'from scratch'. This could be:
- interaction with sockets
- password-related stuff
|
|
|
|
|
Have you tried looking on Google?
Some freeware options:
here[^] and here[^] (POCO has a class implementing POP3 client functionality)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
|
POP3 is pretty simple, but if you want a quick solution, check out IP*Works from nSoftware: http://www.nsoftware.com/[^] (The cost of this is probably less than how much it would cost to write it yourself.)
|
|
|
|
|
Thank you for the replies
During this time my task became more complicated ( ) Now I should not only receive mails via POP3 but also convert body of received mail into plain text (WCHAR* string). I mean: to convert removing formatting elements like HTML tags (when a mail is in HTML format) etc., leaving only text. Now I am not interested in content of attachments - I need only mail's text.
The question is: do you know a component that can solve the task too? Or: one component to read POP3, another one for extracting text from received e-mail. The components may be commercial ones (my employer is rich enough to pay for them
|
|
|
|
|
I have not used IP*Works to the fullest extent, but when I did, I recall that it did everything with POP3 and SMTP. It's a very nice library.
|
|
|
|
|
Hi Everyone,
I'm working on a NT service which calls other Services in another machine. I know that for unit testing we can write stubs for other remote services to test the service. I've searched on the net but i couldn't find any tutorial to do this. Can anyone please tell me how to write stubs (the basic idea, i've absolutely no idea where to start) or direct me to any tutorial that would help me??
Regards,
|
|
|
|
|
You just write a method with the same signature as the 'real' function, and add your own code to return a good or bad status as appropriate. For example the Windows function GetFileVersionInfo() could be coded like this
BOOL GetFileVersionInfo(LPCTSTR lptstrFilename,
DWORD dwHandle,
DWORD dwLen,
LPVOID lpData
)
{
OutputDebugString("My test");
return TRUE;
}
MVP 2010 - are they mad?
|
|
|
|
|
SQL server database can have LSN number(Log sequence number) in 25 digit
so maximum value of that LSN can be 9999999999999999999999999
that is 25 times 999...
I cannot use string to store it because i need to perform some arithemetic operations like addation,substrication on it
so in C++ which datatype can i used to store it.
|
|
|
|
|
s v joshi wrote: C++ which datatype can i used to store it
There isn't.
You may store your number into two __int64 variables.
Another option would be using a big integer library, like, for instance, the GNU GMP.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Is __int256 not an option?
I guess is not standard, but there are quite hits in google for 128 and 256 integers.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: Is __int256 not an option?
A __int128 would be enough. Anyway it is not a built in type. You may find a lot of available solution on the web, I suppose (or you may roll your own, it is amusing...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
does this[^] help you?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|