|
ramz_g wrote: All I'm using is a simple Sqlite database and I'm using simple queries where I have to use the windows logged-in user name.
A service is started before a user logs in to the system, and there might be more than a single user signed in. The simplest way would be to create a small application that writes the username to a file, and to drop it in the Startup-folder.
Alternatively, you might try WMI[^].
I are Troll
|
|
|
|
|
Hi Eddy,
Thanks a lot for the replies..
Eddy Vluggen wrote: The simplest way would be to create a small application that writes the username to a file, and to drop it in the Startup-folder.
I shall use this...
Thanks,
ramz_g
|
|
|
|
|
Good day
I've written code that is very computationally intensive, and therefore would like to use threads to parallel process the data (I've got a duo core pc)
The first solution I though of was to use "Parallel.For()" for the outer loop, but for some reason it corrupts my data.
This is the basic form of the code I want to parallelise:
List<int[,]> largeData;
List<int[]> referenceList;
int answer;
foreach(int[] refArray in referenceList)
{
foreach(int[,] largeMatrix in largeData)
{
answer = 0;
foreach(int ref in refArray)
{
answer += largeMatrix[ref];
}
}
}
"Foreach" might not be the optimal choice for the loops, but I used it here to make the example simpler to understand.
I have tried replacing the first (outer) loop with Parallel.For(...), but then my "answer" value changes, implying that the threads corrupt the answer.
If you could help me with a "safe" approach of computing this in parallel I would greatly appreciate it, since figuring this out with almost no knowledge on threads is a daunting task.
tvb
|
|
|
|
|
you must synchronized your thread using lock, mutex, ...
that is the only way to avoid corruption in your array.
you must split your large array in 2 blocks, and run
the first block in a thread, and the second block in a new thread.
if loop is finished, you can join them together.
Just replacing Foreach with Parallel.For is not the answer.
|
|
|
|
|
Okay thanks, that helped a lot
So when you say split the array in 2 blocks, do you mean run one half of second (inner) loop on a thread, and the other half of the loop on another thread?
tvb
|
|
|
|
|
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx[^]
Learn first how to use a thread. Because it is not for beginner.
Just an easy sample :
You have an array 0,1,2,3,4,5,6,7,8,9
You want to sum it from 0 to 9.
For single thread, you must do it :
0+1+2+3+4+5+6+7+8+9 <- take probably 10ms (for example).
For multi threading, you must do it :
0+1+2+3+4 <- first thread -> resultA (take probably 5ms)
5+6+7+8+9 <- second thread -> resultB (take probably 5ms)
at the end, just sum resultA and resultB. (take all together 5ms, because resultA and resultB are parallel)
So, got it ?
|
|
|
|
|
Yes, got it
tvb
|
|
|
|
|
When syncronizing you would better avoid using mutexes and other kernel primitives.Just use monitors (locks) -they are about 20 times more faster and efficient than the mutexes and the other primitives.
And do not use large matrixes they could damage the app performance use vectors only.
[EDIT]
Replace large matrixes in your code with vectors.Use matrixes with small number of elements only.
Life is a stage and we are all actors!
modified on Wednesday, October 21, 2009 6:04 AM
|
|
|
|
|
Okay thanks,
If you don't mind, could you write the basic idea (in the context of my example code)?
I'm am an abolute noob to threads, so don't know where to start. I will read up on using monitors, but just need to know how the rest of the code would be structured.
tvb
|
|
|
|
|
Here is a nice sample for parallel matrix multiplication.
Life is a stage and we are all actors!
|
|
|
|
|
Oh, and when you say use vectors only, do you mean change the array[,] into array[]?
tvb
|
|
|
|
|
Reason why i'm asking for an example is that I already tried my own method of locking, but my data still got corrupted.
This is the type of code I used...
List<int[,]> largeData;
List<int[]> referenceList;
int answer;
Parallel.Foreach<int[]>(referenceList, refArray=>
{
foreach(int[,] largeMatrix in largeData)
{
lock(largeMatrix)
{
answer = 0;
foreach(int ref in refArray)
{
answer += largeMatrix[ref];
}
}
}
});
I also tried locking the "refArray", but in either case, I got the wrong results...
tvb
|
|
|
|
|
I know I'm repeating myself, however to get maximum performance, you must restructure your data and avoid all locks as they cost CPU cycles and reduce parallelism. Hence, use partial sums that don't interfere with each other, and in the end add them all together once.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
Hi, thanks, but I'm not sure I quite understand
How would I restructure my data, and how do you propose I use partial sums?
tvb
|
|
|
|
|
Is it possible to embed an image to a HTML-formatted e-mail? I don’t want to create a link (with <img src=”http://...”> ).
I’m creating a newsletter mail application.
_____________________________
...and justice for all
|
|
|
|
|
You can embed it, but it won't be viewable in that format ( and it will be bigger ). You can attach it, but it won't be visible unless a mail program chooses to show it, and you sure won't get to say where the image is visible.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
|
I have a hardware connected to the usb which communicates by sending the data.When i will start the application and hardware as a fresh it will work fine.But when i will stop my hardware and run it again it will throw me a exception handle stating that the Access denied for COM1: as you dont have proper rights to the resource.But when i remove the USB plug and re connects my application to the hardware it will start working.
Do anyone know how to reset or re intiallize or reconnect the usb to hardware programitically...?
|
|
|
|
|
How about closing it ?
SerialPort serialPort = new SerialPort(...);
serialPort.Open();
...
...
...
serialPort.Close(); // <- close the connection
serialPort.Dispose(); // <- dispose resources in serialPort, use it if you close your application
|
|
|
|
|
I tried all the stuff u mentioned, but it didnt work.I need to unplug and plug again to make it work.So i am looking is there any way to unplug problematically.
|
|
|
|
|
Probably you are using a thread, and the thread is still active ?
You must end the thread.
What happened if you close your application and start it again ?
|
|
|
|
|
No I am not using any thread.Even i close and run the applicatio i face the same problem.As i mentioned i need to remove and place the cable again to re communicate the data.
|
|
|
|
|
That means, there are something wrong with your USB-COM adapter.
Try to install the newest driver. Probably it's a bug in driver.
|
|
|
|
|
I have updated with the latest drivers and still i face the same issue.
Unfortunately it is not working with any other hardware also.
|
|
|
|
|
Check your system, probably there are some process that watch your COM Port.
If you say "Unfortunately it is not working with any other hardware also",
that means something wrong in your system. That's not .NET problem.
|
|
|
|