Thanks for your reply.. But I have tried Environment.UserName already but it doesn't help, maybe because my service is running at the System level and the environment here is the System and not the user.
Also, I would like to know whether there is any class that actually returns me the Windows Identity object of a specified user.
I am getting the name as "SYSTEM" and not the logged in user's name. And I know that this is because the service is run at the system level.
That's correct. Your service is running with the privileges of the system account.
I can now get the currently logged in user name. But, this requires the user to enter his user name and password when the service is being installed and I do not want that to happen.
It would be a breach in security if you could impersonate that user without them entering a password for their account. Either your database needs to grant access to the builtin system-account, or the service needs to run under it's own account, or you use the users' account.
If you're using SQL Server, then you might want to switch to a SQL-login (as compared to Windows Authentication). You wouldn't want to do that with the 'sa' user, but it would get you started
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.
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.
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)
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.
Replace large matrixes in your code with vectors.Use matrixes with small number of elements only.
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.
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.
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...?
SerialPort serialPort = new SerialPort(...);
serialPort.Close(); // <- close the connection
serialPort.Dispose(); // <- dispose resources in serialPort, use it if you close your application
Last Visit: 31-Dec-99 18:00 Last Update: 26-Sep-23 23:52