2
\$\begingroup\$

I'm polling an ashx handler to check if a specific file is present and return true or false depending on it.

public void ProcessRequest(HttpContext context) { int myId; if (context.IsRequestClean()) { if (int.TryParse(context.Request["id"], out myId)) { var directory = Directory.GetDirectories(context.Server.MapPath("~/App_Data/Files"), "*" + myId, SearchOption.TopDirectoryOnly); if (directory.Length > 0) { if (Convert.ToInt32(directory[0][directory[0].Length - 1].ToString()) == myId) { context.Response.ContentType = "text/plain"; context.Response.Write("true"); } } } } } 

How can I speed the above up?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

If you want a shorter time between file is created until the client is notified, I recomment you implement long-running queries, for example using SignalR.

Then setup a FileSystemWatcher that notifies the query as soon as the file is present.

\$\endgroup\$
3
  • \$\begingroup\$ Short example of how you would do it with signalr? \$\endgroup\$ Commented Jun 29, 2014 at 7:49
  • \$\begingroup\$ I think this tutorial is pretty good:asp.net/signalr/overview/signalr-20/… \$\endgroup\$ Commented Jun 29, 2014 at 7:54
  • \$\begingroup\$ Okay. Saw that. It would be a hectic task to do that now. BTW, I'll take your FileSystemWatcher advice. +1 for that \$\endgroup\$ Commented Jun 29, 2014 at 7:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.