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

  • SEARCH
  • Home
  • 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 9008587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:58:33+00:00 2026-06-16T01:58:33+00:00

I have created a method for reading inbox new messages by using exchange server

  • 0

I have created a method for reading inbox new messages by using exchange server like below.How to add these IEnumerable collection to a Queue and Process each List of item inside the queue asynchronously?

private static IEnumerable<ExchangeEmailInformation> GetInboxItems(ExchangeService service)
{
    var emailInformations = new List<ExchangeEmailInformation>();
    try
    {       
        SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
        var itemview = new ItemView(int.MaxValue);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, itemview);
        Console.WriteLine("\n-------------Result found:-------------");
        service.LoadPropertiesForItems(findResults, PropertySet.FirstClassProperties);

        foreach (var item in findResults)
        {
            emailInformations.Add(new ExchangeEmailInformation
            {
                Attachment = item.Attachments ?? null,
                Body = item.Body.BodyType == BodyType.HTML ? ConvertHtml.ToText(item.Body.Text) : item.Body.Text,
                Subject = item.Subject,
                RecievedDate = item.DateTimeReceived
            });
        }
    }
    catch (Exception ee)
    {
        Console.WriteLine("\n-------------Error occured:-------------");
        Console.WriteLine(ee.Message.ToString());
        Console.WriteLine(ee.InnerException.ToString());
        Console.ReadKey();
    }
    return emailInformations;
}

The below are the process i need to call asynchronously by using each items in the queue

static void AddAttachment(string  subject ,string docId, string user, string fileName)
{
    var url = new StringBuilder();
    url.Append(string.Format("https://webdemo-t.test.com:8443/Services/Service/MyService.svc/AddAttachment?User={0}&Engagement={1}&FileName={2}&DocumentTrasferID={3}", user, subject, fileName, docId));

    Console.WriteLine(url.ToString());
    WebRequest request = WebRequest.Create(url.ToString());
    var credential = new NetworkCredential("user", "xxxx", "xxxx");
    request.Credentials = credential;
    WebResponse ws = request.GetResponse();
    Encoding enc = System.Text.Encoding.GetEncoding(1252);
    var responseStream = new StreamReader(ws.GetResponseStream());
    string response = responseStream.ReadToEnd();
    responseStream.Close();
    Console.WriteLine(response);
}
  • 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-06-16T01:58:34+00:00Added an answer on June 16, 2026 at 1:58 am

    You can start new Task for every attachment. There is no need to think about number of task that you spawn. Tasks doesn’t mapped to Threads 1 by 1.

    foreach (var item in findResults)
    {
        emailInformations.Add(new ExchangeEmailInformation ...);
    
        // start new task
        Task.Factory.Start(() => {
            AddAttachment(item.Subject, item.docId, item.User ...);
        })
    }
    

    This method doesn’t require you to use asynchronous API.

    Another way is to utilize asynchronous API of the WebRequest/WebResponse classes.

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

Sidebar

Related Questions

I have created some application, which is reading from System.in using the following method:
I have created a new method in one of the project's controllers that it
I have created a gem that adds a new method to the class ActiveRecord::Base.
I have created a method for reading a file in Java. The file in
I have created a method that can be called using a stored procedure name
I have created a method to check if the keyboard is used in an
I have created a method that should ideally take a single Account object and
I have created a custom method that will return unique items, together with the
I have created a custom shipping method to show depo-names from which customers will
I have created a UserControl called AutorControl with a method to clear its textbox:

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.