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 8651393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:03:29+00:00 2026-06-12T14:03:29+00:00

I have a class with a bunch of methods in. For example private int

  • 0

I have a class with a bunch of methods in. For example

     private int forFunction(String exceptionFileList, FileInfo z, String compltetedFileList, String sourceDir)
        {
            atPDFNumber++;
            exceptionFileList = "";
            int blankImage = 1;
            int pagesMissing = 0;

            //delete the images currently in the folder
            deleteCreatedImages();
            //Get the amount of pages in the pdf
            int numberPDFPage = numberOfPagesPDF(z.FullName);

            //Convert the pdf to images on the users pc
            convertToImage(z.FullName);

            //Check the images for blank pages
            blankImage = testPixels(@"C:\temp", z.FullName);

            //Check if the conversion couldnt convert a page because of an error
            pagesMissing = numberPDFPage - numberOfFiles;
}

Now what im trying now is to access that class in a thread.. but not just one thread, maybe about 5 threads to speed up processing, since one is a bit slow.

Now in my mind, thats going to be chaos… i mean one thread changing variables while the other thread is busy with them etc etc, and locking each and every variable in all of those methods… not going to have a good time…

So what im proposing, and dont know if its the right way.. is this

  public void MyProc()
    {
      if (this method is open, 4 other threads must wait)
    {
      mymethod(var,var);
    }
     if (this method is open, 4 other threads must wait and done with first method)
    {
      mymethod2();
    }
  if (this method is open, 4 other threads must wait and done with first and second method)
       {
          mymethod3();
    }
         if (this method is open, 4 other threads must wait and done with first and second and third method)
        {
          mymethod4();
        }
    }

Would this be the right way to approach the problem of multiple threads accessing multiple methods at the same time?

Those threads will only access the Class 5 times, and no more, since the work load will be equally divided.

  • 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-12T14:03:32+00:00Added an answer on June 12, 2026 at 2:03 pm

    Yes, that is one of your options. The conditional expression you have, however, should be replaced using the lock statement, or even better, make the method synchronized:

    [MethodImpl(MethodImplOptions.Synchronized)]
    private int forFunction(String exceptionFileList, FileInfo z, String compltetedFileList, String sourceDir)
    

    It is not really a conditional because there is nothing conditional going on here. The next coming thread must wait and then it must go on. It literally sleeps without executing any instructions and then it is woken up from the outside.

    Note also that when you are worried about variables messed up during the parallel execution of a non-synchronized method, this only applies to member variables (class fields). It does not apply to local variables declared inside the method as each thread would have its own copy of those.

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

Sidebar

Related Questions

I have a bunch of functions (methods of a class actually) and I'm writing
Say I have: class Vector3 { float x, y, z; ... bunch of cuntions
I have a class which is essentially just holds a bunch of constant definitions
I have a bunch of class who implement a common interface : Command. And
Let's say that I have a bunch of class instances that serve different purposes,
I have a bunch of business class with autoproperties : public class A {
I have a bunch of entity class (generated by Linq to SQL) with a
I have a bunch of links with the class name row. What I'm trying
I have a bunch of textboxcontrol on my page all with class 'red'. On
Let's say I have a bunch of classes that look something like... class Foo{

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.