|
Beware of Application.DoEvents() ! Using such a terrible line of code can cause chaos, e.g. a second click on the same button can "overtake" the first click somewhere in the middle of execution.
While you can avoid those calls in your code, you'll never be safe when you have to use ThirdParty (often closed-source) code.
|
|
|
|
|
ok.
can i raise event in a thread (Task) and handle this event in the main thread? so task will keep running when event is handled?
|
|
|
|
|
Not exactly (event handlers are always called in the same thread that called them) but if you're talking about a GUI application you can have event handlers that marshal the call to the UI thread if they're called on a different one:
void MyEventHandler(object sender, EventArgs ea){
if(InvokeRequired) {
BeginInvoke(new EventHandler(MyEventHandler), new object[] { sender, ea });
return;
}
}
Using BeginInvoke (instead of Invoke) causes the call to be asynchronous, i.e. the calling thread continues executing while the event handler runs. This is what you requested, but be aware of synchronisation issues with any form of parallel execution. Because you usually don't care about the result of a delegate call, you can ignore the return value and not bother calling EndInvoke at any point.
|
|
|
|
|
OK.
So what will happen if i call an event that is handled in the main thread (not UI thread)?
|
|
|
|
|
help me please...
I'm working thesis now.. anybody have pseudocode about blind watermarking with Discrete Wavelet Transform in C#..??
TQ b4..
|
|
|
|
|
Did you do a search for this (I had to as I have no idea what you are talking about) as there seems to be some pretty good resources already out there[^] - the first hit convinced me I wanted nothing to do with it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi everyone. I have been working on this for what seems like forever and have gotten nowhere. In addition, I have asked for suggestions from others and haven't had much luck with that or searching online. So I figured i would post here and see if maybe someone might have a suggestion for me.
I have an application that makes use of MappedNetworkDrives as the path to the network resources. This works fine. My problem is that the MappedNetworkDrives are not always reconnecting (And never when connected via VPN). However if you go into My Computer and click on the drive it now connects and shows contents. I am looking for a way that I could refresh these drives programmatically when launching my program (When it's shown more than likely as I presume this will take a minute or so) so that this is easier for the user. Does anyone have any idea how I might do this? I'm using C#.
Thanks Again,
|
|
|
|
|
Are you looking for the WNetUseConnection function?
|
|
|
|
|
As Colin suggested you are storing the wrong path, you need to change it to a UNC path[^].
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks everyone for your responses. I will take a look at that. This is my first networked program like this and as our previous program (Developed by another company) used mapped network drives for this purpose, I thought this was how this was supposed to be done.
I greatly appreciate the suggestions and everything.
|
|
|
|
|
Hello to everybody.
I have a library named "mydll.dll".
In this library there is a routine written in non managed C
extern "C" LMUSB_HANDLE PASCAL EXPORT
InitializeDevice(unsigned short usVID,
unsigned short usPID,
LPGUID lpGUID,
BOOL *pbDriverInstalled)
I have to call this routine in C# language. I use dll import
[DllImport("mydll.dll", EntryPoint = "InitializeDevice",
ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr InitializeDevice(ushort usVID,
ushort usPID,
ref System.Guid lpGUID,
ref bool pbDriverInstalled);
When I call InitializeDevice I obtain the error "PInvokeStackImbalance was detected".
If I use CallingConvention.StdCall instead of CallingConvention.Cdecl I don't obtain the error but the returning IntPtr value of the InitializeDevice is always 0 (not correct).
My PC is x86 with OS windows 7. I compile dll as x86.
Can someone help me ? Thankyou in advice
P.S. can you see the thread http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/45398.aspx[^]
modified 2-Feb-12 8:58am.
|
|
|
|
|
I suspect that it is a mismatch in calling conventions.
Your function is declared as PASCAL (which evaluates to __stdcall) but you are trying to call it as Cdecl, which handles the stack a little differently.
Try changing your DllImport to CallingConvention.StdCall
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
If I use StdCall the function will return me IntPtr(0) both in the case the device is connected or disconnected and it is not correct ...
|
|
|
|
|
Griff is right, using the wrong calling convention is likely to corrupt the stack, so you have to take care of that first.
the return value being zero could have many reasons, most probably the function failed to run properly, maybe one of the input parameters has a bad value, your device isn't present, whatever. What would be the expected failure reporting mode of the callee? Does it return zero and set errno or LastError?
Warning: pointers will take 32 or 64 bits depending on your OS and how you build the app.
FWIW: I wrote a little P/Invoke article here[^].
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
YOU ARE RIGHT !!!!
I have mistaken the GUID !!!
Now it works propery !!
|
|
|
|
|
Hi. I am using a C# page to insert data into a table which consists of many columns...
The first column ID which is incremented automatically.
The second column takes input from the front end and is incremented automatically.
Rest columns take input from front end
I use Stored procedure to insert data in the table.
But somehow I find duplicate entries except for first column in the table.
How is this possible? I mean is there an error in my front end coding or is it an error in Sql-server.
Because I tried it myself and it wont allow to enter duplicate values as my logic is perfect and I am inserting values on button click.
But when I fire a query in Sql, it gives me duplicate entries with different ID's only for some records not for all.
Can anybody please help me with that?
|
|
|
|
|
Member 8591985 wrote: is it an error in Sql-server
Certainly not.
Member 8591985 wrote: is there an error in my front end
Possibly.
Member 8591985 wrote: The second column takes input from the front end and is incremented
automatically.
I'm not sure I follow you here.
I suggest you look at your back end code.
|
|
|
|
|
We can't, based on that information.
I would suspect that it is your SP that is at fault, but without seeing it, I can't say what the problem is.
Member 8591985 wrote: it wont allow to enter duplicate values as my logic is perfect
My! Aren't we the lucky one!
Learn to assume that you are wrong: 99.9999% of the time, it will be true. Just because something works when you test it in one specific place, and set of circumstances does not mean it is "perfect" - it just means you haven't found a problem yet.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: it just means you haven't found a problem yet.
aka perfect until proven otherwise.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Perfect?? Really??
Everyone thinks their code is perfect, right up until it explodes on a machine that was not your DEV box.
I've got an app I've written going out to 10,800 machines next week. Even though I've tested it to death on a dozen machines, both XP and 7 and had a mini-pilot, I can no longer find anything wrong when the app is used normally and when I intentionally try and break it. Does that mean that my code is perfect?? Hell NO! It just means there's a test case that I haven't thought of yet.
Am I nervous that I have an app going out to so many machines? You bet your ass I am!! Especially so considering this app was comissioned by a VP and has very high visibility.
Chances are VERY good that its your code that's screwed up and there's some misguided step in your logic that you think is right and it's not, or some condition you didn't think of or are not checking for that's causing the problem.
Member 8591985 wrote: I use Stored procedure to insert data in the table. But somehow I find
duplicate entries except for first column in the table.
AND
Member 8591985 wrote: Because I tried it myself and it wont allow to enter duplicate values as my
logic is perfect and I am inserting values on button click.
Case in point. You're obviously doing something very wrong that is never going to work in a multi-user environment. The logic works perfectly IF and only IF there is one person running your frontend. Your code is probably written for that limitation and falls on its face when used by multiple users because it doesn't take into account two people using the code at the exact same time.
You should be asking yourself (and your logic) what would happen if 2 or more users click on this button at the exact same time.
Member 8591985 wrote: How is this possible? I mean is there an error in my front end coding or is it
an error in Sql-server.
An error in SQL Server itself? Most assuredly not. Is there some problem in your stored procedure AND/OR your frontend code? I'd guarantee it!
|
|
|
|
|
Hi All,
I am creating setup project for window application in c#. I want user to enter few details during installation like username/password. Installation will be continued only if these fields are filled. Can anyone tell me how to validate fields during installation.
FYI: I am using standard Setup Project provided by .NET.
Thanks in advance !
Amit
|
|
|
|
|
|
|
Hi there
Im Fairly new to C#.net, In vb i used to use a function called SaveSetting.
Im Aware that no such function in C#.net Exists
is there any way to do this??
Ian
|
|
|
|
|
I don't know what SaveSetting does in VB.NET, but would this[^] help at all?
|
|
|
|