using (var sr = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Templates/test.doc")))
Thanks Mike, I forgot mention that I was running the codes in my local machine, not on server. I will try your solution and let you know the result.
So if I want the c# class run manually or schedule by Quartz.net, I have to prepare two sets of codes for some statements and identity if the c# is running in manually or through Quartz.net?
This issue can easy fix, by my another question is: I saw most people mentioned the issue "Application pool" for Quartz.net, for my case, my asp.net mvc web app is running as a tool, there are no user to visit it, so after the application is started, the
quartz.net will be triggered immediately through your example codes, and then it will be running every 5 mins, basically, it will send email notice through certain condition (query results) from a DB2 database. so as you mentioned in your website, after the
website is running 20 mins, since the server pool is idle, (nobody visit it), then the quartz.net will not working any more? how to resolve this issue? I may not use it if this issue can not be resolved. Somebody mentioned to add some condition in IIS, no
sure if there is any solution? any idea?
So if I want the c# class run manually or schedule by Quartz.net, I have to prepare two sets of codes for some statements and identity if the c# is running in manually or through Quartz.net?
No, just use System.Web.HttpContext.Current.Server - it works everywhere.
Peter Cong
This issue can easy fix, by my another question is: I saw most people mentioned the issue "Application pool" for Quartz.net, for my case, my asp.net mvc web app is running as a tool, there are no user to visit it, so after the application is started, the quartz.net
will be triggered immediately through your example codes, and then it will be running every 5 mins, basically, it will send email notice through certain condition (query results) from a DB2 database. so as you mentioned in your website, after the website
is running 20 mins, since the server pool is idle, (nobody visit it), then the quartz.net will not working any more? how to resolve this issue? I may not use it if this issue can not be resolved. Somebody mentioned to add some condition in IIS, no sure if
there is any solution? any idea?
So if I want the c# class run manually or schedule by Quartz.net, I have to prepare two sets of codes for some statements and identity if the c# is running in manually or through Quartz.net?
No, just use System.Web.HttpContext.Current.Server - it works everywhere.
Peter Cong
This issue can easy fix, by my another question is: I saw most people mentioned the issue "Application pool" for Quartz.net, for my case, my asp.net mvc web app is running as a tool, there are no user to visit it, so after the application is started, the quartz.net
will be triggered immediately through your example codes, and then it will be running every 5 mins, basically, it will send email notice through certain condition (query results) from a DB2 database. so as you mentioned in your website, after the website
is running 20 mins, since the server pool is idle, (nobody visit it), then the quartz.net will not working any more? how to resolve this issue? I may not use it if this issue can not be resolved. Somebody mentioned to add some condition in IIS, no sure if
there is any solution? any idea?
What do you mean by "running on your local machine"? Is this code in a website in your local IIS? Or is it a console or windows app?
This mvc web app is in developing stage, of course ,it is developing in my local machine and testing in local machine, it is a mvc web application,
it will be implemented to production web server if everything is working well in my local machine. I think every company is doing the same thing as mine.
Member
366 Points
2214 Posts
why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting.com
Feb 26, 2015 11:31 PM|Peter Cong|LINK
Hi, I am following this tutorial to implement Quartz.net in my asp.net mvc web app,
http://www.mikesdotnetting.com/article/254/scheduled-tasks-in-asp-net-with-quartz-net
The following code can be executed by a button action, but after I made the schedule , it has run time error here in debug.
using (var sr = new StreamReader(Server.MapPath(@"\\App_Data\\Templates\test1.doc"))
with this error message of "Object reference not set to an instance of an object."
I found that "Server" returns null, does anybody know why that line of code is different when I execute manually and schedulelly?
TT
All-Star
194428 Points
28073 Posts
Moderator
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 02:19 AM|Mikesdotnetting|LINK
You should try
TT
Member
366 Points
2214 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 07:27 AM|Peter Cong|LINK
Thanks Mike, I forgot mention that I was running the codes in my local machine, not on server. I will try your solution and let you know the result.
So if I want the c# class run manually or schedule by Quartz.net, I have to prepare two sets of codes for some statements and identity if the c# is running in manually or through Quartz.net?
This issue can easy fix, by my another question is: I saw most people mentioned the issue "Application pool" for Quartz.net, for my case, my asp.net mvc web app is running as a tool, there are no user to visit it, so after the application is started, the quartz.net will be triggered immediately through your example codes, and then it will be running every 5 mins, basically, it will send email notice through certain condition (query results) from a DB2 database. so as you mentioned in your website, after the website is running 20 mins, since the server pool is idle, (nobody visit it), then the quartz.net will not working any more? how to resolve this issue? I may not use it if this issue can not be resolved. Somebody mentioned to add some condition in IIS, no sure if there is any solution? any idea?
TT
All-Star
37441 Points
9076 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 07:34 AM|AidyF|LINK
No, just use System.Web.HttpContext.Current.Server - it works everywhere.
http://forums.asp.net/post/5825786.aspx
TT
Member
366 Points
2214 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 08:24 AM|Peter Cong|LINK
Hi Mike, I have just tried it, the HttpContext.Current.Server did not compile so I used
System.Web.HttpContext.Current.Server, but I got the same error, and in debug, the System.Web.HttpContext.Current.Server returns null.
By the way, I am running my mvc in my local macine, not on production server.
any idea how to fix it? thanks
TT
Member
366 Points
2214 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 08:26 AM|Peter Cong|LINK
Hi AidyF, I have just tried it, , but I got the same error, and in debug, the System.Web.HttpContext.Current.Server returns null.
By the way, I am running my mvc in my local macine, not on production server.
any idea how to fix it? thanks
TT
All-Star
37441 Points
9076 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 08:40 AM|AidyF|LINK
What do you mean by "running on your local machine"? Is this code in a website in your local IIS? Or is it a console or windows app?
TT
Member
366 Points
2214 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 10:54 AM|Peter Cong|LINK
This mvc web app is in developing stage, of course ,it is developing in my local machine and testing in local machine, it is a mvc web application,
it will be implemented to production web server if everything is working well in my local machine. I think every company is doing the same thing as mine.
TT
Member
366 Points
2214 Posts
Re: why Quartz.net can not read this line of code? based on the example from: www.mikesdotnetting...
Feb 27, 2015 03:41 PM|Peter Cong|LINK
Finally, I found that this code is working.
System.Web.Hosting.HostingEnvironment
TT