none
LINQ to SQL in Mutithread RRS feed

  • Question

  • Hi,

     

    I'm very new to LINQ to SQL . I have an very Simple requirement. We need to Read a text file (read the content) and  Insert/Update the table. Adding on to it we need to process lots of text files to  minimize the processing time. So for the same i  adopted LINQ to SQL as its provides little more convinience in handling data and Mutithreading(Theadpool) where each thread will focus on single text file for processing and updating the tables. 

    My Questions are as below:

    1. Is my aproach right to achieve my objective

    2. How safe is the the thread would work to update the tables.

    Can you please suggest  me  to proceed on this

     

    Your help is very much appreciated and Thanking you in advance for the smae

    • Moved by edhickey Thursday, November 18, 2010 4:14 PM (From:.NET 3.0/3.5 Windows Workflow Foundation)
    Thursday, November 18, 2010 3:44 PM

Answers

  • Hello,

    1. I think you can use TPL (Task Parallel Library). Here is an example on how to parallelize operations by using ParallelInvoke:
        http://msdn.microsoft.com/en-us/library/dd460705.aspx
        Or use multiple thread (not TPL) and read text files as below:

    2. There are many safety considerations in multi-threaded and database. Please try to be more specific about your concern.

    var lines = File.ReadLines(Path.Combine(
        Environment.CurrentDirectory, @"YourTextFileName.txt"));
     
    var q = from line in lines.AsParallel()
          let fields = line.Split(new char[] { '\t' })
          select new
          {
            name = fields[nameColumn],
            country = fields[countryColumn]
          };
    
    

    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    • Marked as answer by liurong luo Friday, December 3, 2010 6:40 AM
    Thursday, November 25, 2010 7:07 AM

All replies

  • Hello,

    1. I think you can use TPL (Task Parallel Library). Here is an example on how to parallelize operations by using ParallelInvoke:
        http://msdn.microsoft.com/en-us/library/dd460705.aspx
        Or use multiple thread (not TPL) and read text files as below:

    2. There are many safety considerations in multi-threaded and database. Please try to be more specific about your concern.

    var lines = File.ReadLines(Path.Combine(
        Environment.CurrentDirectory, @"YourTextFileName.txt"));
     
    var q = from line in lines.AsParallel()
          let fields = line.Split(new char[] { '\t' })
          select new
          {
            name = fields[nameColumn],
            country = fields[countryColumn]
          };
    
    

    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    • Marked as answer by liurong luo Friday, December 3, 2010 6:40 AM
    Thursday, November 25, 2010 7:07 AM
  • Hello,

    I'm writing to check the status of this thread. Please let me know if you need more help when you feel free. I temporarily mark the reply as answer, if you find it does not help, please unmark it when you are back. Thanks a lot!


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Friday, December 3, 2010 6:40 AM