管理 C# WPF 应用程序客户端 PC 文件夹中的 3000 个文件
我想在用户 PC 上为 WPF C# 应用程序创建一个包含大约 3000 个文件的文件夹。我担心实现后,查找文件名是否会太慢。有人可以建议它是否应该工作,或者是否有更好的选择? 基本上,我的主要目标是使用 Clickonce 将应用程序部署在任何用户 PC 上,并启动它运行,而不需要下载数据库应用程序。
背景: 我创建了一个 C# 应用程序来查找 yahoo Finance 中的相关对。目前,它下载 3000 个交易品种的报价并将其存储在用户 PC 上的 Mysql 数据库中。我有兴趣创建一个不依赖于 Mysql 数据库的应用程序的新版本。我正在考虑将所有引号保存在用户 PC 上文件夹中的单独文件中。不确定这是否是一个好主意,或者是否有其他替代方案,例如在用户 PC 上创建小对象数据库,使用一些辅助类库管理大型数组的缓存等将是理想的。
PS:这是一个开源教育项目,所以我买不起商业产品。
I want to create a folder with around 3000 files on a user PC for a WPF C# application. I am worried whether after I implement, if the lookup of a filename will be too slow. Can someone please suggest whether it should work, or if there is a better alternative?
Basically, my main goal is to use Clickonce to deploy the application on any user PC, and start it to run without imposing requirements of downloading database application.
Background:
I have created a C# application to find correlated pairs from yahoo finance. It currently downloads quotes for 3000 symbols and stores it in a Mysql database on the user PC. I am interested in creating a new version of the application which does not depend on Mysql database. I am thinking of saving all the quotes in a separate files in a folder on the user PC.Not sure if this is a good idea, or if some other alternatives like creating small object database on the user PC, using some helper class library which manages cache of large arrays, etc. would be ideal.
PS : It is an open source education project, so I cannot afford to buy commercial product.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 SQLite 怎么样?除了软件之外,您不需要安装任何其他东西。 这是 .NET 的包装器。
要回答有关查找驱动器上的文件名的问题,这取决于驱动器的类型。如果它是 SSD,可能根本不需要很长时间,如果它是机械驱动器并且您正在使用索引,它也会很快。但是,如果您不使用索引并且机械驱动器速度较慢,则速度会很慢。
如果您确实想要性能并希望将其存储,您还可以考虑 RAM 磁盘 / RAM 驱动器在文件系统上。但是,您还需要将其存储在持久存储中。
How about using SQLite? You wouldn't need to install anything else than your software. Here is a wrapper for .NET.
To answer your question regarding looking up the filename on the drive, that depends on what kind of drive it is. If it is an SSD it will probably not take long at all, if it is a mechanical drive and you are using indexing it will also be fast. However if you don't use indexing and have a slower mechanical drive, it will be slow.
You could also consider a RAM Disk / RAM Drive if you really want performance and want to have it stored on a filesystem. However, you would need to store it on a persistant storage as well.
您可以使用简单的基于文件的数据库,例如 SQLite。
http://www.sqlite.org/
还有一个 .NET 驱动程序。
http://code.google.com/p/csharp-sqlite/
You could use a simple file-based database such as SQLite.
http://www.sqlite.org/
There is a .NET driver for it as well.
http://code.google.com/p/csharp-sqlite/
在这种情况下,我不建议回退到文件系统来代替数据库。您是否考虑过 SQL Server Compact Edition 或 SQLite?两者都在进程内运行,这意味着您不必安装数据库服务器 - 它是应用程序的一部分。当然,它们仍然支持 SQL。
I wouldn't advise falling back to the file system in lieu of a database in this case. Have you considered SQL Server Compact Edition or SQLite? Both run in-process, meaning that you don't have to install a database server - it's part of your application. And, of course, they still support SQL.
3000 个文件就可以了,300,000 个文件就会有问题了:)
唯一确定的方法就是测量!
创建包含 10 个零长度文件、100 个文件和 1000 个文件的文件夹。 。 。 10,000,000。
然后测量在每个文件夹中查找文件所需的时间,您将更好地了解哪些文件夹“太慢”。
PS“太慢”完全是主观的。 10毫秒太慢,还是10分钟太慢?
您需要确定什么是“太慢”并从那里开始工作。
PPS 在决定以这种方式使用文件系统之前请仔细考虑,还有更好的替代方案(如其他分析中所示)。
3000 files will be fine, 300,000 files and you'd have a problem :)
The only way to know for sure is to measure!
Create folders with 10 zero length files , 100 files 1000 files . . . 10,000,000.
Then measure the time it takes to find a file in each of the folders, you'll get a better idea which are "too slow".
P.s. "Too slow" is completely subjective. is 10ms too slow, or is 10 miunutes too slow?
You need to decide what "Too slow" is and work from there.
P.P.S Think carefully before deciding to use the file system in this way, there are better alternatives (as shown in other anawers).
我建议考虑使用 XML 文件来存储 3000 对数据,而不是 3000 个单独的文件,并且您可以使用大量 LINQ to XML 来更快地访问数据。
I would say consider using a XML file to store your 3000 pairs of data, rahter than 3000 separate files, and there are plenty of LINQ to XML you can use to access data faster.
我建议使用(正如您所说,您愿意考虑文件系统的替代方案)Sql Server Compact 4.0。它是:
DataTable
、DataSet< /code> 和一组非常熟悉的基于 SqlServerCe 的
SqlConnection
/SqlDataAdapter
类。您可能能够在很短的时间内实现交换,因为“大部分”工作可以通过向项目中添加对 SqlServerCe 的引用并执行搜索和搜索来完成。将“MySql”替换为“SqlServerCe”。这有点过于简单化了,但也不是太多! =)
I'd recommend using (as you've said that you're willing to look at alternatives to the file system) Sql Server Compact 4.0. It's:
DataTable
,DataSet
and a set of SqlServerCe basedSqlConnection
/SqlDataAdapter
classes that will be very familiar.You'll probably be able to achieve a swap-over in a very short space of time as "most" of the work can be achieved by adding a reference to SqlServerCe to your project and performing a search & replace on "MySql" for "SqlServerCe". That's a slight oversimplification, but not by much! =)