Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7551367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:28:34+00:00 2026-05-30T10:28:34+00:00

Currently I am facing a problem which I am unable to solve after a

  • 0

Currently I am facing a problem which I am unable to solve after a lot of work and search, I asked a similar question before but didn’t got any reply maybe because I didn’t asked it correctly so I deleted that question.

Ok I am downloading emails using MailBEE.net Objects library and it is working fine except that if downloading method is called again while a previous call is still in downloading phase then two copies of messages start to download which is wrong.

on an ASP.net page I am calling an ASHX handler that downloads the emails

    public class sync : IHttpHandler {
    public void ProcessRequest(HttpContext context)
    {
        ApplicationData.layer Functions = new layer();
        context.Response.ContentType = "text/text";
        int messageCount = Convert.ToInt16(context.Request.QueryString["messageCount"]);
        if (Functions.SyncMail("email", "user", "password", "pop.gmail.com", messageCount) == "Successful")
        {
            context.Response.Write("New Messages Downloaded.");
        }
        //context.Response.Write("Hello World");
    }
}

I am calling the above ASHX handler using Jquery from another (ASPX) page

<script type="text/javascript">
        $(document).ready(function() {
            asyncLoad();
        });
        function asyncLoad() {
            document.getElementById("CustomerDetails").innerHTML = "<img alt='' src='Images/ajax-loader.gif' />" + "&nbsp;&nbsp;<span>Downloading New Messages...</span>";
            $('#CustomerDetails').load("sync.ashx?messageCount=" + "10");
            callAgain();
        }
        function callAgain() {
            setInterval(asyncLoad, 20000);
        }
</script>

The purpose is to keep on calling sync.ashx after some time (The 20000 delay) to check new messages, the problem is if one call of sync.ashx is busy in downloading messages and a new call is made during this time, it starts to download identical copies of messages since it does not find the ids of emails in database which previous call is going to make.

I need some sort of mutually exclusive access, that if once call is busy in downloading messages then another call should not be made.

Something like

if(IsAlreadyDownloading == False)
{
Functions.SyncMail(params)
}

Where IsAlreadyDownloading is a global flag or mutex that should be set True once one call start downloading and be set false once it finish downloading or some exception has occurred indicating that another call can be made safely.

Since it is an ASP.net application we don’t know when user will navigate away from the page which start download call and when it will navigate back to that page so another call to download handler should be made or not.

I don’t know if I explained it properly or not but I hope someone will understand. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:28:35+00:00Added an answer on May 30, 2026 at 10:28 am

    Finally after much hair pulling and head scratching I managed to solve this problem, I don’t know if it’s the best solution but at least it is working properly now, if you know a better solution please share it here, thanks.

    Here is my solution.

    I used global.asax to declare application level global variable named as follows

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["IsAlreadyDownloading"] = false;
    }
    

    The purpose is to mimic mutex like behavior and for that I left sync.ashx file and made another an aspx file, the reason for shifting from ashx file is access application level variable IsAlreadyDownloading which is unavailable in a generic handler. The code of aspx file is as follows

    <%@ Page Language="C#" %>
    <%@ Import Namespace="ApplicationData" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            int messageCount = Convert.ToInt16(Request.QueryString["messageCount"]);
            ApplicationData.layer Functions = new layer();
            try
            {
                if (!Convert.ToBoolean(Application["IsAlreadyDownloading"]))
                {
                    Application["IsAlreadyDownloading"] = true;
                    if (Functions.SyncMail("email", "user", "password", "pop.gmail.com", messageCount) == "Successful")
                    {
                        Response.Write("New Messages Downloaded.");
                        Application["IsAlreadyDownloading"] = false;
                    }
                    else
                    {
                        Response.Write("<p>Unable to download some messages</p>");
                        Application["IsAlreadyDownloading"] = false;
                    }
                }
            }
            finally
            {
                Application["IsAlreadyDownloading"] = false;
            }
            Response.End();
        }
    </script>
    

    No matter how many times we make call to this page the method will not work as it will find IsAlreadyDownloading = true if another call of method is busy in work, as soon as it will finish it will again set IsAlreadyDownloading = false so a new call can acquire it.

    Hope this help someone in similar problem.

    server

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently facing a strange problem in PHP. I have two scripts, index.php which
I'm currently working a lot with DDD, and I'm facing a problem when loading/operating
I'm facing a problem in C++ for which I currently don't have an elegant
I'm currently facing a more mathematical problem. I'm developing an application which is interested
I am currently facing a, in my opinion, rather common problem which should be
I am currently designing a public-facing C++ API for a product which will require
I'm facing a huge problem here which is driving me crazy, I've made an
I am currently facing a serious problem. I use the standard django admin interface
I am currently facing a very disturbing problem: interface IStateSpace<Position, Value> where Position :
We are facing one problem in managing test data (xmls which is used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.