|
I have a MDI app, with view based on CHtmlView. Is there any way to launch every CChildFrame in separate thread ? If yes, how can I do that ? I search on internet for this, but I have found nothing ...
|
|
|
|
|
The frames belong to the GUI and should be therefore executed in the GUI (main) thread. I even don't think that it is possible to run the child frames in another thread due to the relationship to the main frame, and the views. Even if it is possible, it would be a nightmare to make it all thread safe.
But you can execute specific operations within the child frames or the views in separate threads. A common method is to use worker threads for longer running jobs. Because such threads can not directly access (MFC) UI elements, they have to post (user defined) messages to update UI elements.
|
|
|
|
|
My task is to run some specific html pages, but sending some forms inside these page is taking a little more time, and there is 8-10 html pages ... I was thinking that running every child frame in separate thread would be a good solution ... but I guess is not ... hmm ... I don't know how to shrink the time when these html pages work their tasks ...
|
|
|
|
|
You can still use threads to do the work and provide some kind of wait indication (cursor, status line, or self closing notification / progress window).
The advantage of using threads is that the GUI is not blocked and the user can do other operations meanwhile.
But using threads is not making something that requires an amount of time running faster (besides splitting the work and letting multiple threads perform the work in parallel). It just allows doing something else meanwhile.
|
|
|
|
|
You are perfectly right. Here is the scenario: I should start 8 CHtmlViews, every one of them with a specific web address, and do a login form. Now, every login task, take 3-4 seconds. If a do this for every 8 pages, the time until all 8 pages complete the login is ~30, 35 seconds, but, most important, the main thread, the GUI thread is blocked.
That is why I am trying to run every CHtmlView on separate thread, not because the login task is taken less time, but because is not block the main GUI thread ...
|
|
|
|
|
Put the communication tasks into there own threads and display a place holder in the view meanwhile. Once the communictaion is done, update the view with the data received in the background.
|
|
|
|
|
Unfortunately, the communication with the server is done by html page ...
|
|
|
|
|
If have not used CHtmlView so far but I'm quite sure that the networking is done in a separate thread and there are notification messages informing you when a page has been loaded. Anything else would make no sense because a large download would block your GUI.
If your GUI is blocked, you are probably waiting somewhere inside a loop instead of handling notifications.
|
|
|
|
|
This is a good news. So, I will launch view after view to do a login to see how is moving my GUI ... if I think well, there is some methods on this CHtmlView which reveal that all tasks inside html gui is made somewhere in backside (I guess):
CHtmlView::OnBeforeNavigate2
CHtmlView::OnDocumentComplete
CHtmlView::OnDownloadBegin
CHtmlView::OnDownloadComplete
CHtmlView::OnNavigateComplete2
CHtmlView::OnNavigateError
CHtmlView::OnUpdateUI
modified 17-Jul-18 1:57am.
|
|
|
|
|
I have few methods, in a CDocument class, which read from IHTMLElement get_tagName.
BSTR bstrTagName;
CString sTempTagName;
if (! FAILED(pElem->get_tagName(&bstrTagName)))
{
sTempTagName = bstrTagName;
sTempTagName.MakeLower();
AfxMessageBox(sTempTagName);
SysFreeString(bstrTagName);
}
which show in MessageBox html tags: input, div, span, and so on ...
if I try
BSTR bstrTagName;
CString sTempTagName;
if (! FAILED(pElem->get_tagName(&bstrTagName)))
{
sTempTagName = bstrTagName;
sTempTagName.MakeLower();
TRACE("%s\n", sTempTagName);
SysFreeString(bstrTagName);
}
I have in my debug window the first letter of every read tag:
i
d
s
and no entire html tag ... why in MessageBox I see whole word, but in TRACE macro I don't ?
|
|
|
|
|
The debugger does not always recognise that a character array may be Unicode, so you need to add the type to the variable name or address in the watch window.
|
|
|
|
|
You may need to add ,s or ,u to the variable being watched in the Watch window.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
In watch window I can see the variables with their values normally, the problem is when I want to see them with TRACE macro, in my debug window ...
|
|
|
|
|
_Flaviu wrote: the problem is when I want to see them with TRACE macro, in my debug window ... Try %S instead of %s .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks - I've been looking for a few days for this solution. Works a treat
|
|
|
|
|
You are calling the TRACE macro with a char* format string but pass a CString which is wchar_t* with Unicode builds.
Use one of these:
TRACE(_T("%s\n"), sTempTagName.GetString());
#ifdef _UNICODE
TRACE("%ls\n"), sTempTagName.GetString());
#else
TRACE("%hs\n"), sTempTagName.GetString());
#endif
TRACE1("%s\n", sTempTagName.GetString());
Note also that I have used GetString() instead of the implicit CString LPCTSTR operator.
|
|
|
|
|
After creating a pthread, i am setting the thread id to a custom id using a map.
pthread_t threads[noOfThreads];
struct thread_data td[noOfThreads];
thread= pthread_create(&threads[i], NULL, startFunc, (void *)&td[i]);
setID(threads[i], td[i].thread_id);
SetID function
setID(pthread_t pid, int id ){
thread_ids[pid]=id;
definition of map
std::map<pthread_t, int> thread_ids;
I want to get the mapped value based on the key value in the following function but dont know how to do exactly.
getID function
getID() {
if (thread_ids.find(pid) ==thread_ids.end()) return -1;
return thread_ids[pid];
}
I am very beginner so spare me if i am making a stupid mistake and please point that and help me correcting it
c++, pthread
modified 13-Jul-18 12:04pm.
|
|
|
|
|
Why are you using a struct for a simple value, i.e. int? And why do you need to map the real thread id to some other value? It is not really clear what you are trying to do.
|
|
|
|
|
I am planning to have more variable in the struct e.g.
struct thread_data {
int thread_id;
const char *message;
double result
};
Richard MacCutchan wrote: And why do you need to map the real thread id to some other value?
The application in which i am creating pthreads is a simulation environment on top of which my actual thread scheduling library will execute so the each pthread act like virtual core. Each core(pthread) has its own work package queue from which it retrieves the package for execution and when it is empty it attempts to steal from other cores(via work stealing method). Every core has a package manager singleton class which is responsible for adding and getting the package from the queue. In order to access the other cores(using the singleton class) i need the mapping so that whenever each core access the package manager class (and its queue), it do based on the custom id.
I hope i explained it better this time
|
|
|
|
|
Quote: whenever each core access the package manager class (and its queue), it do based on the custom id. Why not the real id?
|
|
|
|
|
Hi all,
Tt's a HTML Input box like this.
<input id="testInput" name="testInput" value="" tabindex="0" />
and for some reason, I cannot use ASP.net textbox.
However, I need to disable it when a button is clicked (I tried both AUTOPOSTBACK and non-AUTOPOSTBACK button) .
I tried the followings in c# but none of these works.
Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('testInput').readOnly = true;");
Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('testInput').disable= true;");
Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('testInput').disable= 'true';"); '
Please advice, thanks!
|
|
|
|
|
|
Would you ever do something like this:
std :: map<double, MyType, std :: less<double> >
I don't see a reason why not to do it, but I have a bad feeling doing it.
Any Remarks / objections?
Ok, this double - Key is a user Input with a known/limited number of decimal places. I could also take this into acount and use a
std :: map<int, MyType, std :: less<int> >
But why I should?
Btw: Performance is out of questions, the map size is Maximum 10 items.
Thank you very much in advance.
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
In 64bit code (so using XMM registers) it'll probably work, unless any DLL secretly changes a rounding mode on you and "forgets" to set it back. In 32bit code (usually using the x87 FPU stack), who knows? The danger there as usual is that keeping a double in an FPU register keeps it at whatever value was actually computed (which depending on how stod works internally may have bits set in the part of the 64bit significand that extends beyond the 53 bits you usually get) while storing it to memory and reloading it changes the value, and this is something that compilers think is a normal part of how they work so they do it outside of your control, though you can force a store/reload to get a safer value to work with. So it may still work, but there are some sneaky conditions that may depend on specific codegen choices the compiler makes.
|
|
|
|
|
Thank you so much!
To be honest I don't get all of your explanations at the moment. But the most important Thing is, that you Point out, that there can be a Problem... and that corresponds with "my bad Feeling".
So now it will be my part to investigate more for possible pitfalls
Thank you very much again.
[Edit]
And please flag your Response as an answer, it is much more than a "general"
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|