-2

I have doubt for implementing Multithreading with my application.

My Application structure ::

OS : Windows 7 code language : C#, .NET windows Database : .db (file database) Database access :: SQLite, Spatialite

Application logic : (3 part)

  1. Getting values from Database and aftersome modification inserting into database again in new table(temp1)
  2. Getting values from Database and aftersome modification inserting into database again in new table(temp2)
  3. Running query on 'temp1' and 'temp2'

Here, what I am thinking is.

I can create 2 threads which can run individually on 1st and 2nd. 3rd is dependent on 1st and 2nd.

but I think both 1st and 2nd thread is can't process because they both are working on same database (file).

Is my logic write ?

Hardik
  • 259
  • 1
  • 2
  • 17
  • 1
    If I understand your question ... Databases are thread safe by default so you don't have to worry about thread 1/2 conflicting with each other. Use `Thread.Join` to make sure you don't start thread 3 till the first two have finished! – drew_w May 21 '14 at 13:06
  • but this is file database (.db), still it will create and insert record into database parallel ? – Hardik May 22 '14 at 05:46
  • After research for answer.. I got two links 1. _"SQLite, regardless of what threading mode it is in, will lock the database file, so that multiple processes can read from the database at once but only one can write."_ [Stackoverflow](http://stackoverflow.com/questions/11058098/interprocess-sqlite-thread-safety-on-ios) 2. 5.0 Writing to a database file _"Only one process at a time can hold a RESERVED lock"_ [SQLite](http://www.sqlite.org/lockingv3.html) – Hardik May 22 '14 at 06:21

1 Answers1

0

As I mentioned above with File database it's not possible. But still I need to do. So I make my logic like below.

  1. I made copy of that file.
  2. Made 2 threads and parallel start two thread on that databases.
  3. Before 3rd thread start I am combining output into one file database and then running the query.
Hardik
  • 259
  • 1
  • 2
  • 17