|
Hi,
What i am trying to say is .. I have created an e mail message with custom headers with smtp.emailmessage . When this email is received , it would get forwarded or replied to. But i believe on any such action(forward or reply to) all custom headers get removed and new headers are added by the redirecting server. I have certain information in the custom headers that i have created which i would like to retain when i receive the forwarded message. Is there any work around for this. I am willing to make changes in my implementation to any extent as long as it meets my primary objective to get some information across..
Thanks..
|
|
|
|
|
Hi there,
I have a situtation, I am on my way to build an alarm application which will run in the background and will intimate the user for an event which he had set before. Exactly what a scheduler or alarm clock does.
I will explain the design in short here. I maintain the tasks set by the user in a list of "Task" class. With every tick of the timer I initiate a background thread that will poll the task list to check if there are any tasks for the present time stamp. If yes it will raise an event which does the work of intimating the user by playing a music and displaying a form.
The, back ground thread is needed so that the main thread does not have to wait for the scanning of the list.
So far so good. The application is working well. But I know at heart that the List is not a good thing to use in this case as the application will terribly fail if the list is too long. may be the user will be intimated 2-3 mins after the time he may had set his alarm to.
I request for suggestions about which data structure to use here, if not list. I know there are some very fast list like structures (Like something used by the word suggesting thread of the MS Word, as it can pick up words from huge ocean of words.). However I dont know what they are and how to use them. If you suggest a design change, I whole heartedly shall agree. I know it is not a very good design.
Sincerely looking for your suggestions.
Best Regards,
Sid
|
|
|
|
|
Hi,
I would use a list, however I would keep it sorted on due time.
that way the timer's tick only has to check the first entry of the list.
Each time an alarm fires, it gets removed from position zero (which causes the list to shift).
So the only times the length of the list is relevant is when a new alarm is added, or an elapsed one is removed.
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.
|
|
|
|
|
Thanks very much Luc for your answer but the sorting+processing of the list is to be done on everyalarm raise event. i.e every time an alarm is fired, I will have to sort the list and also remove the task. If i got ur your idea prioperly then the sorting of list will also have to be done whenever a new event is added.
If these operations take more than a minute then the calcualtions may go wrong.
How do you suggest a solution then?
Best Regards,
Sid
|
|
|
|
|
Huh?
When an alarm fires, it is the first in the list; removing it does not require a re-sort.
Adding an alarm requires a sort. It would take millions of entries before a sort would take a minute to execute.
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.
|
|
|
|
|
Got the idea! Thanks Luc.
Best Regards,
Sid
|
|
|
|
|
Hi,
I have created an application which runs on a Web Server. This web server in-turn runs as a windows service.
This windows service's account is configured as follows
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
Now I have a scenario in which I have to access a database and execute queries in it which needs the currently logged in user. The problem is that whenever I try to use
System.Security.Principal.WindowsIdentity.GetCurrent().Name
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.
I can change the ServiceAccount as
serviceProcessInstaller.Account = ServiceAccount.User
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.
Hence is there any other way in which I can get the WindowsIdentity object of the currently logged in user? Please suggest..
Thanks,
ramz_g
|
|
|
|
|
|
Hi stancrm,
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.
Thanks,
ramz_g
|
|
|
|
|
ramz_g wrote: System.Security.Principal.WindowsIdentity.GetCurrent().Name
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.
ramz_g wrote: 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
I are Troll
|
|
|
|
|
Hi Eddy,
Thanks a lot for your reply..
Eddy Vluggen wrote: It would be a breach in security if you could impersonate that user without them entering a password for their account.
Yes I understand that.
Eddy Vluggen wrote: If you're using SQL Server, then you might want to switch to a SQL-login
No, I'm not using SQL Server. 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.
So, is there any way that I can obtain the logged in user name alone?
Thanks,
ramz_g
|
|
|
|
|
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
|
|
|
|