博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# Resolve SQlite Concurrency Exception Problem (Using Read-Write Lock)
阅读量:5105 次
发布时间:2019-06-13

本文共 1711 字,大约阅读时间需要 5 分钟。

This article describes the c# example to solve the problem of SQlite concurrent exception method. To share with you for your reference, as follows:

Access to sqlite using c#, often encounter multithreading SQLITE database damage caused by the problem.

SQLite is a file-level database, the lock is the file level : multiple threads can be read at the same time, but only one thread to write. Android provides the SqliteOpenHelper class, adding Java’s locking mechanism for invocation. But does not provide similar functionality in c#.

The author uses the ReaderWriterLock to achieve the goal of multi-thread secure access.

using System;using System.Collections.Generic; using System.Text; using System.Data.SQLite; using System.Threading; using System.Data; namespace DataAccess { / public sealed class SqliteConn { private bool m_disposed; private static Dictionary
connPool = new Dictionary
(); private static Dictionary
rwl = new Dictionary
(); private static readonly SqliteConn instance = new SqliteConn(); private static string DEFAULT_NAME = "LOCAL"; #region Init // Use single case , Solve the problem of initialization and destruction private SqliteConn() { rwl.Add("LOCAL", new ReaderWriterLock()); rwl.Add("DB1", new ReaderWriterLock()); connPool.Add("LOCAL", CreateConn("\\local.db")); connPool.Add("DB1", CreateConn("\\db1.db")); Console.WriteLine("INIT FINISHED"); } private static SQLiteConnection CreateConn(string dbName) { SQLiteConnection _conn = new SQLiteConnection(); try { string pstr = "pwd"; SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder

转载于:https://www.cnblogs.com/mschen/p/8268499.html

你可能感兴趣的文章
Solaris11修改主机名
查看>>
latex for wordpress(一)
查看>>
如何在maven工程中加载oracle驱动
查看>>
Flask 系列之 SQLAlchemy
查看>>
iframe跨域与session失效问题
查看>>
aboutMe
查看>>
【Debug】IAR在线调试时报错,Warning: Stack pointer is setup to incorrect alignmentStack,芯片使用STM32F103ZET6...
查看>>
一句话说清分布式锁,进程锁,线程锁
查看>>
Hash和Bloom Filter
查看>>
SQL Server获取月度列表
查看>>
python常用函数
查看>>
python 描点画圆
查看>>
FastDFS使用
查看>>
服务器解析请求的基本原理
查看>>
VUE源码解析心得
查看>>
[HDU3683 Gomoku]
查看>>
【工具相关】iOS-Reveal的使用
查看>>
数据库3
查看>>
存储分类
查看>>
下一代操作系统与软件
查看>>