473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Need programming help

153 100+
IT"S A LONG QUESTION.PLEASE BE PATIENT TO READ IT.
I HAVE EXPLAINED IT TO MY MAXIMUM CAPACITY.

I am making one app. in which i need to create a seperate access database for each day.

Its a call charging software which monitors the calls made by extensions (just like the hotel rooms).

Now there is GUI, in which there is richtextbox, a treview, and a menustrip.

The treeview shows information about the all the extensions and others.
The user when opens the app can see the treeview on left,richtextbox at bottom and menustrip (at top).

The user can change the nodes when required(and correspondingly the changes are commited to the database)

There is also one "start" button which starts the monitoring.
Now the user can ONLY see the treeview,expand the nodes and scroll the richtextbox when the app. is monitoring (when the start button is clicked) .

They cant change the nodes while the app is monitoring.

For changing they will have to stop it, so that the GUI thread becomes free for not-so-important thing:changing the nodes text (and database)etc because :

There is one serial port component(created at GUI thread) which monitors incoming strings and fetch the data(duration,date,extno. and blah blah) which is very imp (it cant miss even a single incoming string !)

What i am doing is, when the event Data_received of the serial port fires , i create a seperate thread and pass the string as argument(so that the details of teh calls made can be saved in database) so that the GUI thread becomes free and can handle the next incoming string.
Also, the data is stored in a file whose name is same as the day(12/04/08)
I have two main questions :

(1) HOW would I manage the seperate access file for each day?
I can do this:
a)When the app runs for the first time verify that that the database for current day is created or not.(if no create one.)
b)create a thread called DatabaseCreator, which is like this

Expand|Select|Wrap|Line Numbers
  1. while(true)
  2. {
  3. If(today's database not exists)
  4.      create one;
  5. }
but this will be a wastage of thread, so i need more efficient solution.
Why i am so desperate the create the database is coz the serial port in GUI thread wants to store the details in today's database !I If it does not find one it will wait till it becoems available (waiting means the next string wont get processed or will be in Queue which i dotn want)
SO this wont work
Expand|Select|Wrap|Line Numbers
  1. while(true)
  2. {
  3. If(today's database not exists)
  4.      create one;
  5. else
  6. Thread.sleep(one hour or so)
  7. /*oops the datareceived cant find the databse for today it's 12:00:01 midnight ! And  I last woke up at 11:50 and again slept.I will wake up at 12:50 to check(12:00:00 to 12:50:00 data not stored !)*/
  8. }
(2) WILL the expansion and collapse-ation , maximisign and minimising of the app will create fa problem for dataReceived event coz the event will be fired in GUI thread??

Thanks for ur patience to read it.
Jan 15 '09 #1
3 2000
vekipeki
229 Expert 100+
Hi!

First of all, there is one question which pops out immediately: Why do you want to make a new Access file every day? The point of having a database is to have it all in one place, so that, by making queries, one can easily extract and filter the information he needs.

Presuming there is a valid reason for this, this is what you can do:

1. To create an Access database in C#, you can use the ADO Ext. library: How to create an Access database by using ADOX and Visual C# .NET.

2. Why can't you just create your file when handling SerialPort.DataReceived? When the event is triggered, check if the file exists and create it if needed. You should avoid using "while (true)" constructs or and Sleep(time) in a loop, since there are usually better ways of triggering code (timers, events, semaphores etc.)

3. If you cannot or don't want to create a file when handling SerialPort.DataReceived, you can queue your messages together with a time stamp in DataReceived handler ("producer" thread), and handle the complete queue in a different thread ("consumer" thread). Google it (this is an example of producer/consumer: How to: Synchronize a Producer and a Consumer Thread (C# Programming Guide)). Note that handling the data immediately (2.) is still the simplest way, so find a good reason to skip it before going for multithreading.

4. If you are talking about SerialPort.DataReceived event, that event is never fired from the GUI thread. SerialPort has a different thread internally which fires that event. It also has an internal buffer so that it can run asynchronously (received bytes are queued to this buffer from the driver's buffer in a separate thread).

Having that in mind, note that you won't be able to update the GUI while handling the DataReceived event without getting the Cross-thread exception, but you didn't mention that for now, so I presume you are not updating anything in that event.
Jan 15 '09 #2
akshaycjoshi
153 100+
Thanks vekipeki !

(1)
You asked me why should i create a seperate access file for each day.
You see if I create a single file for storing the details of all the calls it would get full sooner or later causing my application to crash.
I know that the calls made in one day can no way fill up the access file created for that day but this way I can see on the safe side.

I had thought that while searching so many access files I would do this

while(file !=null)
{
execute the query corresponding to this file
fill it in the datagrid

move the file pointer to next file
}

Although this is not the most efficient thing but atleast It will protect my program from getting crashed.

(2)
Also. i will just embed a blank ms access database file with my ap and just copy it to the application folder and renaming to that day's name.

(3)
You said that the DataReceived event will get fired on a seperate thread and the messages get buffered , so no messages will be lost.
That sentence made me really happy :)

(4)
You asked why dont I check the presence of file during DataReceived event.
I thought that it will create unnecessary headache for the event and that because of this checking-for-presence and creating-if-not-present thing will make my application lose some of the strings.
But after u told me that the strings get buffered, this should not be a big problem and i will implement what you said.


(5)

I wanted to leave access and go for more robust Sql server Express but it's installation is the problem.I guess it would be too diff. for them to install it attach the database, set the connection string in app.config.
So i went for Access.

Can u sugest anything better than this ?

THANKS A LOT vekipeki
Jan 15 '09 #3
vekipeki
229 Expert 100+
Note however that serial port buffers are limited, so handling an event with a large baud rate and continuous incoming data means that you should nevertheless take care that you don't waste too much time in your handler.

If you create your database once a day, then it shouldn't worry you too much, but the safest way (although harder to implement) in any case would be using producer/consumer threads. In that case event handler would simply update the queue and end the DataReceived thread immediately. If you have enought time to implement it, you will get a piece of code that is reusable in other apps regardless of their baud rates or processing amounts.

Moving to SQL server would be easier if your Access database were in a single file, meaning you would then only change your data layer slightly. There are some articles about SQL server deployment (e.g. CodeGuru: Deploy SQL Databases Easily with the Installer Class) that might help you if you decide to go in that direction.
Jan 16 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
1
by: mch2k2 | last post by:
Hello All I have just started working on Pyhton. I need urgent help regarding Python Network Programming. I want the elctronic version of the Book: Foundations of Python Network programming by...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
4
by: Web_PDE_Eric | last post by:
I don't know where to go, or what to buy, so plz re-direct me if I'm in the wrong place. I want to do high performance integration of partial differential eqns in n dimensions (n=0,1,2,3..etc) I...
9
by: Brian Hampson | last post by:
I am trying to determine all the groups which the current user has permissions to add a member. Here's my code: foreach (System.DirectoryServices.SearchResult ADSearchres in...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
8
by: Amar | last post by:
I am a system programmer , doing my program in C/RedHat LINUX ES4.0 version. I want to do concurrent programming in C , which will utilise my system's 4 processor simutaneously. I need some one's...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.