|
If you are writing a GUI application, the main GUI thread is event driven and will handle an event and execute all code for that handler before returning to the code that raised the event. If you are writing a multithreaded application, the background thread works independently of the main thread and would not be interrupted unless its listening to events as well.
|
|
|
|
|
AFAICT your suggestion has two major drawbacks, memory-wise:
1. it repeats the leading symbols over and over;
2. for each new chunk of license plates it costs a pointer.
I'd consider an N-tier approach; for N=2 that would be some data structure for the rightmost say 3 symbols, and then a second layer of structure to hold all of those, representing the remaining symbols.
The first one could be a run-length as you described, or a linked list, or switch from one to the other scheme depending on the population.
The second one could be a full array, or maybe a dictionary.
Maybe a 3-tier approach would be optimal: an array for 2 symbols (36^2 elements), pointing to an array for 2 symbols, pointing to an array for 2 symbols, holding a 36-bit bitmask for the last symbol. (Yes it would work better if there were only 32 symbols in the alphabet used).
Note: the "pointers" above don't have to be real pointers, they could be indexes into a huge array, requiring say 4B each rather than 8B.
And the simplest approach that might be good enough would be a Dictionary<string,long> where the key holds the first N-1 symbols, and the value is a bitmask covering the last symbol.
PS: this is what I was going to reply to your vanishing question in Algos
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.
|
|
|
|
|
Lol... saw that forum was dead, so I moved it over here .
|
|
|
|
|
That is exactly how forums die.
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.
|
|
|
|
|
Luc Pattyn wrote: That is exactly how forums die. "Not with a ! (bang), but by forum transmigration," T.S. Elliot did not write in "Hollow Men."
"Our life is a faint tracing on the surface of mystery, like the idle, curved tunnels of leaf miners on the surface of a leaf. We must somehow take a wider view, look at the whole landscape, really see it, and describe what's going on here. Then we can at least wail the right question into the swaddling band of darkness, or, if it comes to that, choir the proper praise." Annie Dillard
|
|
|
|
|
1. your threads do whatever you make them do, and will continue to do so.
And events get handled by either the main aka GUI thread, or one of the threadpool threads. See here[^].
2. If you have long winding code that executes on the main thread (e.g. in a button click handler), then other GUI events (and Windows.Forms.Timer tick events, and more) will be stalled. That basically is why long winding operations should NOT be executed by the main thread.
3. If other threads need to access WinForm GUI components (Controls), you need to use Invoke. See 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.
|
|
|
|
|
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.
|
|
|
|