|
Good reference. I always use the self-marhsalling approach for any event handler that does not come in from MY event handlers as they may be running on an alternate thread. I much prefer BeginInvoke to Invoke to avoid blocking issues -- IMHO, BeginInvoke should be the default pattern unless there is reason to block the caller or there is some other reason why the calls need to be syncronized. Typical MVC scenarios don't require such coordination, an event happens, the UI handles it by posting a message to itself, and when it gets context, it updates itself.
|
|
|
|
|
vtpdawg wrote: IMHO, BeginInvoke should be the default pattern
I don't agree. When SetText() is the method to set a Control's Text property, and you call it from the main thread, it does not invoke a thing, and runs synchronously. Calling it from another thread should not behave differently. If synchronous operation is not guaranteed, then call it SetTextSynchronouslyOrAsynchronously!
vtpdawg wrote: I much prefer BeginInvoke to Invoke to avoid blocking issues
Delegating towards the main thread should never take long as in a well designed app the GUI is always responsive, hence the main thread itself basically does not block.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Sometimes you WANT your background thread to update a GUI object, and you KNOW there won't be any race condition. .NET has a convenient way of disabling cross-thread checking for a given class:
Label.CheckForIllegalCrossThreadCalls = false;
This disables the annoying cross-thread complaints from .NET (in this case for Label objects) when you know there won't be any conflicts.
|
|
|
|
|
... and wait for the app to break later long after you've finished it and can't work out why - It's easy enough to handle it the correct way so I see no point in taking this risk.
Dave
"My code works, but I don't understand why!" - DaveyM69 (Me) BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Note the qualifier, "...and you KNOW there won't be any race condition...".
|
|
|
|
|
Problem -: How to add an function in existing dll. For eg: Suppose 'Abc 'is a dll and is referenced in an xyz project, now i want to add function in 'Abc' dll such that i dont to rereference the xyz project.
|
|
|
|
|
I am not quite sure if I understand correctly.
I wonder if extension methods are what you are looking for. .NET 3.5 Extension methods are a way of adding functionality to an existing type.
Read more here
Cheers,
Daniel
|
|
|
|
|
Actually i don't have code of Abc dll and i want to add a function in that. and this Abc dll is referenced in my xyz project.
Now if i use extension method then i have to create separate namespace 'bcd' and then create a new extension method on that and then if i build my project a new dll will be created which i don't want.
|
|
|
|
|
Member 6392036 wrote: Now if i use extension method then i have to create separate namespace 'bcd'
Says who?
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:29am.
|
|
|
|
|
exactly i dont have any source code of that dll yet i want to add a function in that dll. how can i do that.
|
|
|
|
|
Without resorting to hacking the binary, you can't!
|
|
|
|
|
Below is the header file.can anyone please give a idea to call the callback function below.
Dll name is client.dll
//Function Prototype
int PASCAL EXPORT RegisterCallbackFunctions (TCallbacks CallbackFuncs);
//Data Structure
struct TCallbacks
{
LPONUSSDREQUEST m_pOnRequest;
LPONUSSDRESPONSE m_pOnResponse;
};
//Prototypes
typedef int (*LPONUSSDREQUEST) (HANDLE hLoginInstance, HANDLE hDialog, DWORD *pdwAppParam);
typedef int (*LPONUSSDRESPONSE) (HANDLE hLoginInstance, HANDLE hDialog, char szString [ ], DWORD dwAppParam);
I have already got the hloginInstance and hDialog functions,But I need help in calling the callback function.
regards,
Jeanix
Sh@Re
modified on Monday, October 26, 2009 6:48 AM
|
|
|
|
|
You need to post this in the C++ forum if it is a header file.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Hi friends, can someone explain me the difference between the two Method of Monitor class? Becouse with VS2010 the TryEnter Method will will become obsolete.
Thank you.
Bye bye
|
|
|
|
|
Monitor.Wait is not a replacement or alternative for Monitor.TryEnter. The current method
bool TryEnter(Object obj) is being obsoleted because the suggested replacement is
void TryEnter(Object obj, ref bool lockTaken) So there isn't really any major change, just that the boolean will now be returned as a by ref parameter instead of a return value from the method.
(If you want to know the reasons for why the old TryEnter is being made obsolete you can read about it here[^])
Monitor.Wait()[^] is totally different. It basically releases the lock on an object and blocks the current thread until a different thread called Monitor.Pulse() to signal that the thread can reacquire the lock and continue.
Simon
|
|
|
|
|
if i write this way, then it works:
System.Diagnostics.Process.Start(@"C:\\if.log");
But if i want the text from other label like label3.Text, and it has the same path, then it doesnt work.
System.Diagnostics.Process.Start(@"{0}", label3.Text);
I make the user to open the file, then the label saves the file path and if the program needs to open the file, then it doesnt work, it works only if i write the path myself. Maybe someone knows how to use this method without saving the path to a label, then that would be better. Can someone help me with this please?
modified on Monday, October 26, 2009 6:32 AM
|
|
|
|
|
With the second way, you don't need to type double slashes into the text box because the text box already handles this. Could that be the problem?
You also don't need the @ sign if you are putting double slashes in the string. (Or keep the @ sign and you don't need to use double slashes.)
If not, try posting more details about what "doesn't work". Does it cause an exception? Post the type, message and a stack trace from the exception.
Simon
|
|
|
|
|
Thank you Simon, it worked without @ . The double slashes are because it puts automatically when it gets the path. I have tested it, to see how looks the path, and it used double slashes.
|
|
|
|
|
slavakr wrote: it worked without @
Cool.
The double slashes are because the single slash in a string is an escape character, so you can't just have one on it's own. The first escapes the next character.
So in the string "c:\test" the \t will become a tab (see here[^])
So instead it's common to put "c:\\test" which means the first slash just escapes the second and the string will become a correct path.
If you want to have a string without escape characters, you can put the @ sign at the beginning, and it will not use any escape sequences in the string. So @"c:\test" will not escape the t like it would if you missed out the @ sign. So with the @ sign in place, there is no need to use double slashes.
There's more about escape characters on Wikipedia[^]
Simon
|
|
|
|
|
C# newbie here.
I am using the wonderful John’s Background Switcher[^] to keep my wallpaper fresh and interesting, and I realized I'd like to make use of it for my screen saver, too.
Since he does not have an option for that, I thought I'd try learning how to make a little C# screensaver form that just showed the wallpaper as is.
That was about a week ago.
In my experiments, I decided there are two general ways of solving this problem:
1) create a blank desktop and display it with no apps running (or my own app, which wouldn't do anything but listen for a keypress)
2) hide everything on the existing desktop, leaving only the wallpaper visible
I have found code samples for creating desktops, but nothing that I can figure out how to make work with my tiny brain. So I concentrated on option 2.
This requires 3 steps:
a) hide all shortcut icons
b) hide all running taskbar icons [& the taskbar]
c) make wallpaper visible through my app's form
C seemed pretty easy from my Java perspective: just throw up a glasspane and be done. C# begs to differ with me.
I did finally find a way to keep my app transparent enough without allowing click-thru (mouse clicks activating the visible icons behind my transparent form), or so I think. Regardless, it won't matter if I hide everything that shouldn't be shown.
I have just now figured out how to reliably hide shortcut icons and redisplay them at will. This problem was a lot harder than it should have been because everybody seems to say "icons" when they mean the stuff on the taskbar (naturally, I assumed they'd use the term tasks or some such - silly me). But now it's good.
So now I am stuck on step B - hide everything else. I did find a PInvoke for toggling the desktop, but it has some nasty drawbacks:
- it requires including a DLL with the screen saver executable
- it does not let me know if things are visible or not
- the restore does not put things back the way they should be
I really think the first option is best (create an empty desktop), but I don't know how to make that work. If anyone has the right solution...
Barring that, does anyone know how to "properly" hide all desktop icons, and then how to restore them as they were?
No code shown because my stuff is a horrible mess and would only make this post even more confusing. But I'll post whatever bits are requested, and of course when I get it working I'll share the whole finished steaming pile of code.
よろしくおねがいします。
Narf.
|
|
|
|
|
It seems like you are overcomplicating the problem.
I don't understand why you don't just make your app full screen and display the required image over the top of everything else.
Simon
|
|
|
|
|
Well, obviously the big factor here is learning. I'm doing this because I want to know something about C# and Windows APIs and stuff.
But more specifically to your point, because the "required image" changes from time to time. The wallpaper changer automatically pulls down random images from the net.
In order to reproduce all of that functionality, I'd have to do something very complex indeed, and that's definitely beyond the scope of my little project.
My app IS fullscreen, because it has to cover all the other apps and prevent them from receiving keystrokes/mouse movements. I had to make it transparent so I could see the stuff below, but do that without letting the mouse clicks or keystroke slip through.
In Java, that means a glasspane. In C#, it means a headache. At least so far as I know. Total newb here.
Narf.
|
|
|
|
|
|
No, it's Windows that is making my life miserable. I am just trying to learn how to make use of the APIs to do something that, conceptually at least, is very straightforward.
The second link is one I already used. I think it was the third one I found for making C# screen savers. Also, Visual Studio 2005 comes with a screen saver learning kit, and I used that one, too. I know the basics already.
But my only problem now is I want to view the wallpaper - and nothing else - beneath my transparent pane, while still preventing any keystrokes etcetera from getting through.
Technically my problem is not knowing how to do that, but that's why I'm asking for help.
The first link is also interesting, and I may want to look at it later, but it's for a different kind of project than what I am trying to do here. Thanks anyway.
Narf.
|
|
|
|