m-jansen
asked on
Convert something to C#
How to convert this to C#?
If DateDiff("d", Application("LastScheduled Run"), Now()) > 0 Then
' This is where you put the commands you want to run on the
' schedule set up by the above condition.
Response.Write "Do Something!"
' Reset our "LastScheduledRun" variable to the current date
' and time indicating we just did it.
Application.Lock
Application("LastScheduled Run") = Now()
Application.UnLock
End If
If DateDiff("d", Application("LastScheduled
' This is where you put the commands you want to run on the
' schedule set up by the above condition.
Response.Write "Do Something!"
' Reset our "LastScheduledRun" variable to the current date
' and time indicating we just did it.
Application.Lock
Application("LastScheduled
Application.UnLock
End If
ASKER
Take a look at this link. This is where I got the code.
http://www.asp101.com/articles/john/schedule/default.asp
http://www.asp101.com/articles/john/schedule/default.asp
ASKER
And read under Method 1: Faking It
if(((TimeSpan)(Application ["LastSche duledRun"] - DateTime.Now)).Days > 0)
{
Response.Write("Do Something");
Application.Lock();
Application["LastScheduled Run"] = DateTime.Now;
Application.Unlock();
}
{
Response.Write("Do Something");
Application.Lock();
Application["LastScheduled
Application.Unlock();
}
ASKER
if (((TimeSpan)(Application[" LastSchedu ledRun"] - DateTime.Now)).Days > 0) // Error 3 Operator '-' cannot be applied to operands of type 'object' and 'System.DateTime'
{
Response.Write("Do Something");
Application.Lock();
Application["LastScheduled Run"] = DateTime.Now;
Application.UnLock();
}
{
Response.Write("Do Something");
Application.Lock();
Application["LastScheduled
Application.UnLock();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Label4.Text = (((TimeSpan)(Convert.ToDat eTime(Appl ication["L astSchedul edRun"]) - DateTime.Now)).Days).ToStr ing();
Always gives me the value:
-732509
Why? It should be bigger than 0 the first time I run the script on the server?
Always gives me the value:
-732509
Why? It should be bigger than 0 the first time I run the script on the server?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>Also make sure that you initialize Application["LastScheduled Run"] the first time.
I'm not sure about this.... When to do it? In the contructor? If I use the dev server in VS2005 does this work? Or must I use IIS to test this?
I'm not sure about this.... When to do it? In the contructor? If I use the dev server in VS2005 does this work? Or must I use IIS to test this?
ASKER
This code
Label4.Text = (((TimeSpan)(DateTime.Now - Convert.ToDateTime(Applica tion["Last ScheduledR un"]))).Da ys).ToStri ng();
gives me
732511
After I refresh the page this one should be negative?
Label4.Text = (((TimeSpan)(DateTime.Now - Convert.ToDateTime(Applica
gives me
732511
After I refresh the page this one should be negative?
No - it depends on what the original value is in the Application["LastScheduled Run"] variable.
You can set this in your global.aspx file when the application first loads. Or you could set it on the page that uses it. It is really up to you as to where it goes or when to do it.
But this is getting beyond the scope of the question.
The code provided is the translation of your code converted to C#. How you decide to implement it or put it in different places is really up to you.
You can set this in your global.aspx file when the application first loads. Or you could set it on the page that uses it. It is really up to you as to where it goes or when to do it.
But this is getting beyond the scope of the question.
The code provided is the translation of your code converted to C#. How you decide to implement it or put it in different places is really up to you.
ASKER
how to initialize Application["LastScheduled Run"] ?
ASKER
Application["LastScheduled Run"] gives me the current time when hitting refresh. I have placed Label5.Text = Application["LastScheduled Run"].ToSt ring(); in the Page_Load. I thought this should give me the last time I ran the page. Is that right?
If you set it to that then yes.
ASKER
I'm not so sure about this one
Application["LastScheduled Run"]
yet
How long does this one contain what I have set it to? Until the server goes down?
Application["LastScheduled
yet
How long does this one contain what I have set it to? Until the server goes down?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can u tell me what is : Application("LastScheduled