|
Thank you kindly, that also works.
Glenn
|
|
|
|
|
you appear to be talking to yourself
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You may be a tad slow, however your hearing is OK.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Dare I say... 'Pardon?'
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Half cooked? What's going on?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
williamnw wrote: Half cooked?
Very Good
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job.
<pre>using System.Timers;
public class usersession
{
private static bool sessionalive;
private static Timer usertimer;
public static bool SessionAlive
{
get { return sessionalive; }
set { sessionalive = value; }
}
public static void BeginTimer()
{
try
{
SessionAlive = true;
//usertimer.Start();
usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString()));
usertimer.Enabled = true;
usertimer.AutoReset = false;
usertimer.Elapsed += new ElapsedEventHandler(DisposeSession);
}
catch (Exception ex)
{
return;
}
}
private static void DisposeSession(object source, ElapsedEventArgs e)
{
try
{
SessionAlive = false;
}
catch (System.Exception ex)
{
return;
}
}
public static void ResetTimer()
{
try
{
SessionAlive = true;
usertimer.Stop();
usertimer.Start();
}
catch (Exception ex)
{
return;
}
}
}
</pre>
as you can see begintimer function set the property SessioAlive to true and then instantiate the timer.when that time arrives the disposesession fires and set the property to false.on my main form the constructor calls the begintimer function through startsession function <code>public frMain()
{
InitializeComponent();
StartSession();
//SessionChecker();
}
public void StartSession()
{
try
{
usersession.BeginTimer();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
</code>
so any time the user click on something, i check the usersession.SessioAlive property like so inside this switch case snippet
<code>case "transfer":
if (!usersession.SessionAlive)
{
new LoginForm().ShowDialog();
}
MessageBox.Show("cash back transfert page");
break;
</code>
and inside the loginForm if login is correct we call the usersession.ResetTimer() and resettimer set SessionAlive property to true then the user can work again until there is no activity until session expores again.
<code>
this.DialogResult = DialogResult.OK;
usersession.ResetTimer();
this.Close();
</code>
It's working just fine.Now i really wanted the checking to be run in background(the commented sessionchecker on the main form) that's were i need your advice.here i use forms.timer on the main form to create a small job but since forms.timer doesn't have autoreset it doing an endless loop by calling the loginform and i have to stop the process from the task manager.
<pre>
private void SessionChecker()
{
try
{
check = new Timer();
check.Enabled = true;
check.Interval = 1000;
check.Tick += new EventHandler(check_Tick);
}
catch (Exception)
{
throw;
}
}
void check_Tick(object sender, EventArgs e)
{
try
{
if (!usersession.SessionAlive)
{
new LoginForm().ShowDialog();
check.Stop();
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
</pre>
How to make the cheking being run in the background and when session expires block the application by asking credentials?I can't really see the mistake i'm doing.But since it's not working as expected i'm doing something wrong.Can you help me solve this?Thanks for reading
eager to learn
|
|
|
|
|
Hi there,
Although your idea is not bad, i find it a rather strange way of doing an expired session...
what i would do ( although i am no coding god either so feel free to correct me)
For example you want your session to be valid for 15 Minutes:
You simply make a Session variable like:
session.Item("expirationtime") = DateTime.Now().AddMinutes(15)
then, on every call you make that is < session.Item("expirationtime") , you set this again
if(session.item("expirationtime") < DateTime.Now())
{
}
Seems a hell of a lot simpler and has better performance then spinning of threads to keep timers ticking.. (500 visitors logged in means 500 threads running a timer)
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
hello thanks for the reply and sorry for the late response.i didn't check my mail lately and thought(sorry ) this subject doen't interest anybody.I'm not sure i understand what you are trying to explain but i have a good news.My same codes is working silly enough from me i put the check.stop(); after calling the loginform.so i did call it before and reset the winforms.forms.timers object on formclosing too.i did some tweak to it.that part was changed to
if (!usersession.SessionAlive)<br />
{<br />
check.Stop();<br />
if(logininstance == null)<br />
logininstance = new LoginForm();<br />
logininstance.ShowDialog();<br />
<br />
<br />
}<br />
thanks a lot!
eager to learn
|
|
|
|
|
Ok so recently the following question came up in an exam:
Which three of the following should not be applied to optimize a windows application
Now the two possible answers of interest are:
- Frequent Boxing and unboxing
- Throwing exceptions
The way I understand the question is basically saying: "Which of these will slow down a program".
And in the text book it basically says both boxing and unboxing and throwing exceptions is costly.
Now according to the exam writers only one of those is right. I had both of those checked(and the other one that isnt relevent). But they say only "Throwing exceptions" is correct.
So yeah, just wanted to find out if i was crazy or not.
:P
|
|
|
|
|
They're probably basing it on the relative "cost" of each. Throwing an exception can take a very long time - much longer than boxing or unboxing.
Still, if you want to get pedantic, you can say that a lot of boxing/unboxing will give a greater slow down than one exception, and you should only use exceptions in "exceptional circumstances" where it's likely the program won't be able to continue anyway.
Come to that, if you really want to optimise things, you should avoid using interfaces, iterators, properties, and a load of other C# features as well, since they're expensive at run time...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: if you really want to optimise things, you should avoid using interfaces, iterators, properties, and a load of other C#
Fixed that for you!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Although C# is pretty fast if you use it carefully...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: C# is pretty fast
And getting faster - upto 9.8 m/s/s faster
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Just curious, where that you get that value? (this is not a "citation needed!", I just like benchmarks)
|
|
|
|
|
I think he just threw it up in the air (think about it )
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
I would agree, thou it's a bit of a tricky one. Although both are costly, 'Throwing Exceptions' will benefit the application (i.e. errors will be handled and therefore must be an improvement). I think the problem with the question is the use of the word 'optimize' as that gives the impression of improving performance. I guess in this case it's meant to mean improving the application as a piece of software.
Just out of interest, what was the third option?
EDIT:
Oh, which should not be used... Well then surely that's an invalid question.
Am I right in saying that the Q&A is suggesting that you should use 'Frequent Boxing and Unboxing' to optimize a windows application?! Why the hell, in any situation, would adding more work optimise anything. The only thing that made 'Throwing Exceptions' valid is that it has benefits.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
"Which three of the following should not be applied to optimize a windows application"
What I get from this is: What will slow down an application.
Now there were 5 possible answers, I dont actually remember the rest but basically they say that only the Throwing exceptions one is correct and im saying that boxing/unboxing will also "not optimize an app".
Thanks for your thought guys, the voices in my head stopped for a second there.
|
|
|
|
|
|
You're not crazy. Unless you're misusing exceptions for general control flow (instead of exceptional control flow), (un)boxing is more likely to be a performance problem. Exceptions are not supposed to happen - so it doesn't matter that they're slow.
|
|
|
|
|
The application I am writing, the user has to right click on the file and tell the file to Run As and login with a admin account. Is there a way to tell if the user that is logged in running the program is a admin or not? This is in XP not vista.
|
|
|
|
|
Hi,
this is a snippet I once used, it shows "User" or "User, Administrator" IIRC:
List<string> roles=new List<string>();
try {
Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal wp=new WindowsPrincipal(WindowsIdentity.GetCurrent());
foreach(object roleName in Enum.GetValues(typeof(WindowsBuiltInRole)))
if (wp.IsInRole((WindowsBuiltInRole)roleName)) roles.Add(roleName.ToString());
} catch (Exception exc) {
log(exc);
}
log("Windows role = "+string.Join(", ", roles.ToArray()));
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi,
I've added a setup project to my solution and added the project output from a windows App. The install worked fine.
I then changed 2 settings in my config file from User settings to Application settings. Rebuilt the projects and tried to re-install. The config file did not get updated in the installed version. I'm using vs2008.
I even tried removing the setup project and creating a new one. But, the old config was still installed! How is the Setup Project still referencing the old config file? I click on the project output in the setup project and select "Outputs". This gives me the directory to the config file. I've checked this and it does point to the correct version of the config file. So I'm confused as to why the config file isn't changing.
Any ideas?
Thanks.
|
|
|
|
|
Sorry for replying to my own post.
I've tried this again in anther solution. Just added a Win App and a setup project to the solution. I added some Application settings to the app.config file and installed. Then Changed the Application settings to User Settings and re-installed. The config did change on the second install so now I am really confused.
The only thing that I can see that I am doing differently in my main solution is Changing the Assembly Version number. Would this affect the Config File not being correctly installed when using the Setup Project?
|
|
|
|
|
Hi,
I know I'm not getting much input on this but I've just deleted the Setup project and added again but with a different Project name and this worked. This has got me over the problem short term but I'm worried what will happen when I need to upgrade my project.
Last attempt but has anyone got any ideas? I've tried changing the version number of the setup project and setting "RemovePreviousVersion" to true but everything I tried just didn't work.
|
|
|
|