Perfect, the idiom you use is definitely more elegant :) glad I learned something new today. As for the deadlock, I'm quite sure why it happens (the "pump" that does the Invoke requests doesn't get called as the whole thread is stuck waiting in the first place), no problems there. thanks a lot for your time! ;)
CaesarCZ
Posts
-
Threads and TextBox -
Threads and TextBoxUm, coming from C++, I would have thought calling a function from two different threads might cause some re-entrancy issues when working on a common resource (the TextBox's content they both try to update). I would have expected the output to be either interleaved ("AAAA" and "BBBB" resulting in "AABABBBA" for example) in the better case, or some variable corruption in the worse case.
-
Threads and TextBoxHi, thanks for the answer... good to know about the queue :) I think you confused the SetText (aka the snippet) thing though. Unless C# does something behind my back (not that I'd be surprised :rolleyes: but I guess it would require the CLR to detect the caller of the Invoke method and recall it, and on top of that, it would render the delegate parameter useless), SetText doesn't get called again, so the deadlock is not due to the SetText method recursively calling itself in another thread (in fact, the deadlock only happened in certain cases and required a lot of tries to replicate in each of those cases). In other words, "as the basic concept of the construct is that SetText, when called on a thread other than the GUI thread, causes itself to be executed once more, on the GUI thread" seems wrong to me :) Just going over it here so that I know I'm not mistaken...
-
Threads and TextBoxHi, still getting to know C# and recently stumbled upon a problem I'm not sure about. I have two threads, each of them updating a WinForm's TextBox. I'm using the usual InvokeRequired:
if (this.OutputConsole.InvokeRequired)
{
this.OutputConsole.Invoke(
new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
text
);
}
else
{
this.OutputConsole.AppendText(text + "\r\n");
}But bad things happened when I tried to add some sort of locking to that :~ o. I just added a lock around the above mentioned code
lock(ConsoleLock)
{
// the snippet from above
}A deadlock occured, the thread that actually needs the Invoke gets the lock ("user thread"), and tries to call Invoke, "delegating" the code to the thread that created the control ("original thread"). The original thread, though, wants to write something to the TextBox too, and is stuck waiting for the lock, currently held by the user thread, which in turn keeps waiting for the original thread to process the delegated call. So far, so good. The question is: if I remove the lock, why does it still work okay... is the TextBox, in some way, thread-safe? Is it due to the way the Invoke call works (and if so, how does it work in the first place)? I don't really see how I could make it work using locks anyway (as long as I have to use the above mentioned paradigm), do you see how it could be done? thanks for your time :)!
-
adding virtual webcamhello, I'm capturing input from a USB webcam, do some filtering on the video and would need to output it to another, this time virtual, webcam device that I somehow need to add to the system (WinXP SP2). Even a .NET solution is okay with me (though I doubt there is some). 1) would I need a custom device driver to do that? 2) if not, which way should I go? thanks
-
Point of Intersection -
unicode fontshello, I'm developing an application that should be able to display names of people from various corners of the world (ie, lots of languages at once). For that, I'd really like to be able to create a font that could handle all the unicode characters (or at least some kind of roman alphabet subset, but with all the punctuation and stuff, so that ie. Goethe would spell Gothe with an umlaut etc). I'm not sure such fonts are even installed (WXP). I tried CreateFontIndirect, but since not even the LOGFONT structre has any attribute that would take "make it a unicode font", I don't know what to do next (and I really don't want to store language informoation and create multiple fonts etc). Any hints? PS: I also tried looking at unicode.org, but still I'm unable to render most of the fonts
-
vertically scrolling a listboxwonderful, both approaches work. Thanks
-
vertically scrolling a listboxhello there, I would like to scroll my CListBox (in other words, not a CListCtrl or CListView!) so that a certain item is the topmost visible item in the list (having it visible is not enough). Any ideas? I tried SetScrollPos, and although the range is meaningful, only the scrollbar gets "scrolled" (the bar moves), but the listbox itself doesn't move. I'm getting quite desperate and all i can find if horizontal scrolling everywhere. thanks
-
Beginner's Guide to DirectXI believe DirectDraw isn't officially supported since DX8. That means you still can use it, but you won't find documentation for it (last is in DX7 SDK I believe). Make sure you're on WXP as AFAIK that's what DX10 needs. Also, I believe LPDIRECTDRAW4 is surely older interface than necessary, try LPDIRECTDRAW7 or LPDIRECTDRAW6. As for setting up VC 6.0: set up the prober include and library directories as you did. Move them both to the top of the list! Otherwise, it won't work (at least with DX8 I've been using). You also need to link some libs... like ddraw.lib and maybe dxguid.lib, depending on what parts of DX you use (look in the libs directory and use common sense). I believe you should better use D3D to draw graphics. As for links, gamedev.net has some nice articles and good forums for this kind of stuff (in the forum FAQ for D3D, you can even find links to some page that has older SDK for download if you want DD documentation). A nice tutorial is at http://www.andypike.com/tutorials/ . If you just want to do 2D with D3D, look up Sprites in the SDK. Also, there are some nice tutorials in the SDK's help files. Haven't touched DX since DX8/9, so if there's something new specifically to DX10, sorry :(
-
OT: OBEX push, but on linuxHello, I'm trying to push using OBEX Object Push profile (and via Bluetooth, that means the BlueZ stack) on Linux (I'm sorry, I know this forum is more about Windows, but maybe someone could help me here). I have no problem pushing the the file using the routine from the ussp-push tool. But what I'd need is to be able to push multiple files simultaneously to multiple devices. I keep getting a "device busy" message. Probably a problem with socket blocking or something, but I'm not a network specialist (and not even a linux specialist, first time i work with it ;)). Anybody has done that, has an application that does that and can gimme the source code's URL or any other hints? PS: google - doesn't find anything, but I'm not even sure what the problem is though, so I might be googling for the wrong term.
-
Two successive dialogs in a dlg appThank you both guys, it works now:)
-
Two successive dialogs in a dlg appdlg = new CPoolDlg; m_pMainWnd = dlg; int nResponse = dlg->DoModal(); delete dlg; playoff_dlg = new CPlayoffDlg; m_pMainWnd = playoff_dlg; nResponse = playoff_dlg->DoModal(); delete playoff_dlg; That's the code in InitInstance. I have to say I'm in no way a MFC guru. I played with the code a bit to make the CPoolDlg and CPlayoffDlg members of the CMyApp, and had to make them * in order to be able to create them after the common controls initialization is done. If I comment the first dialog out, the second runs wo problems, if I don't, the DoModal returns -1 (from what I know on some message pump checking call)
-
Two successive dialogs in a dlg appHello, I'd like to run two successive dialogs in my dialog application. The problem is that when the user exits the first one and the application tries to run the second, it fails (I suspect the message pump gets destroyed). I've tried creating a dummy window (so that there would always be at least one message target) before running the first dialog but that didn't help) Any helps? Can I re-ren the pump again or prevent it from ceasing? Thanks
-
IXMLDOMxxx functionsHi, After having some trouble making all those XML libs running with Win32, I decided I'd use the MSXML SDK. But it all seems to be messed up somehow. I have downloaded teh MSXML version 3, and I can't get samples from MSDN running (namely http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthgetattributenodemethod.asp uses a method called get_documentElement, which neither compiles for me, neither is noted in teh SDK chm file.). God, all I want is to parse a simple file, get the values between XML tags and the eventual attributes in them. So far, I was able to selectSingleNode a piece of the XML, but what am I supposed to do now? How do I read the values, the attributes... I'm either getting it all wrong or it's a total mess. Thanks
-
CString into a non-MFC appI know I'm being annoying, but does it have the same interface as teh MFC's CArray. Can I use it as a drop-in replacement (after a typedef of course) PS: I'm really sorry to be such a pain, but I really don't do MFC/ATL/WTL stuff at all (yes, I've looked up MSDN... lists less member functions that CArray, but it's only the ATL CSimpleArray - just really not sure about it all) thanks
-
CString into a non-MFC appCould you also, please please please, tell me if it has this CArray? Before I download and install it... Thanks
-
CString into a non-MFC appThanks... I found it at http://www.codeproject.com/string/stdstring.asp... seems nice, unfortunately it also uses CArray (I'm currently looking if I might replace it somehow myself). Still if you new a way to add MFCs CArray (and CString eventauly) to a non-mfc project (I guess I'll have to link to the MFC dll anyway... All I need it to do is to be a WinAPI app that makes use of MFC... sounds weird, doesn't it... )
-
CString into a non-MFC appHi, I'd like to use a XML parsing library (http://www.codeproject.com/soap/markupclass.asp) that uses CString (I guess that's the only MFC thing it uses). I'd like to use it in a pure WinAPI app, is there a way to add CString there:confused:? (which files/libs to link, never worked with MFC really). An alternate solution would be another XML library. Thanks for your answers
-
Getting around vanishing pointersI guess there is not. The CTreeItem only stores the pointers you give him, not the actual data. So if you delete the data, the pointer the CTreeItem has is useless. Why don't you just delete them once you stop using the CTreeItem? (I have never worked with MFC etc, but this is a common practice)