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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:47:00+00:00 2026-05-31T00:47:00+00:00

I have a distributed client server system which has multiple ‘worker’ engines and a

  • 0

I have a distributed client server system which has multiple ‘worker’ engines and a WCF service, lets call it, FileManagerService, which adds ‘jobs’ to a database for the ‘worker’ engines to pick up and process.

The database consists of two tables: Jobs and File. Every job operates on a File ( many to one relationship ). Multiple jobs can be added to the Jobs table at once, they are processed in the fashion of a queue.

Example of Job‘s are actions such as : MoveFile or DeleteFile, etc.

I am trying to achieve mutual exclusion on the File record by using a ‘locked’ ( bool ) column in the File table itself.

The mutual exclusion zones that I think are needed are within the WCF service FileManagerService‘s method: addJob() and within the ‘worker’ engines’ TakeAndProcessAJob().

At the moment I am having trouble with working out how linq-to-sql deferred execution and how the linq-to-sql transaction system works.

I currently have the following method which is supposed to take a Job from the Jobs table, check if its related File is locked, if it is locked we will return nothing, if it is not locked we will lock the File and return a Job, and delete that Job from the Jobs queue:

public static Job GetAnAvailableJob()
{
    using (DBDataContext db = new DBDataContext())
    {
        DataLoadOptions loadOptions = new DataLoadOptions();
        loadOptions.LoadWith<Job>(f => f.File);
        db.LoadOptions = loadOptions;
        var jobAvailable = from ja in db.Jobs
                                    where ja.File.locked == false
                                    select ja;
        var jobToTake = jobAvailable.FirstOrDefault();
        // This file temp is here so that we can return
        // an associated File with the Job.
        // We delete
        File fileTemp = null;
        if (jobToTake != null)
        {
            fileTemp = jobToTake.File;
            jobAvailable.File.locked = true;
            Console.WriteLine("Locked file:" + fileTemp.FileID);
            db.Jobs.DeleteOnSubmit(jobToTake);
            db.SubmitChanges();
            jobToTake.Asset = fileTemp;
        }
        return jobToTake;
    }
}

The ‘worker’ engines TakeAndProcessAJob() basically does the following: Call GetAnAvailableJob(), if return object is not null -> proccess the job, if it is null -> sleep.

The WCF Service FileManagerService uses this locking method:

public static bool LockAsset(long FileID)
{
    using (DBDataContext db = new DBDataContext())
    {
        var fileToLock = db.Files.Where(f => f.FileID == FileID && f.locked == false).Single();
        if (fileToLock == null)
        {
            return false;
        }
        else
        {
            Console.WriteLine("Locked File:" + fileToLock.AssetID);
            fileToLock.locked = true;
            db.SubmitChanges();
            return true;
        }
    }
}

What do I need to change in these two methods to make then behave in a transactional manner and have mutual exclusion on the File record. Currently I am getting change conflict exceptions – row not changed or found – on the SubmitChanges() within the TakeAndProcessAJob() method.

Thanks

  • 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-31T00:47:02+00:00Added an answer on May 31, 2026 at 12:47 am

    I could not figure out the answer to my question and so I did some logic restructuring and devised a workaround using plain old SQL. To lock the record I now use a single line ( atomic ) command on the record:

    UPDATE dataTable SET locked = 'True' WHERE (locked = 'False') AND (recordID= 15)

    I then use SqlDataReader and check the RecordsAffected field. If records have changed, it means that I have successfully locked the record. If records have not changed, it means the record is already locked, and so I return false on my locking method.

    The process that is trying to lock the record then sits in a while loop calling lockRecord and waiting for a successful callback.

    I’m not sure if it was completely necessary to make the switch from LINQ to SQL. I made the logic changes in my application, and the switch to plan SQL at the same time and so it is difficult to identify if using LINQ was THE problem.

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

Sidebar

Related Questions

I have written a simulator of a client-server based distributed file system. Now to
I have one server and three clients in which a windows service is running
I have worked on several distributed client/server projects recently, and one pain point that
I have client server application using distributed object. some time my code is working
I have a distributed app that sends data via WCF to a server to
With a distributed application, where you have lots of clients and one main server,
I have a distributed C++ application, which is composed of 4 processes spread on
If I wanted to have Python distributed across multiple processors on multiple computers, what
Lets say that I have only DHT (distributed hash table) implemented (in Python), and
I know .net has WCF, which I believe was touted as the replacement for

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.