473,763 Members | 6,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need programming help

153 New Member
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,richtextbo x 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(creat ed at GUI thread) which monitors incoming strings and fetch the data(duration,d ate,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 2024
vekipeki
229 Recognized Expert New Member
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.Data Received? 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.Data Received, 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.Data Received 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 New Member
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 Recognized Expert New Member
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
2461
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 last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
1
1863
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 John Goerzen. If anybody among you have that please forward at my mailID. Thank you in advance. Manjeet Chaudhary
45
3047
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
3894
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
4
2850
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 want to do (fast) graphic output of the results. I used to use C. I want to upgrade my computer. Do I get dual core? Does C# support dual-core? Is C# as fast as the old C? Is there a new C? (or is C# the new version of C?) Is Visual Studio...
9
5254
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 ADSearch.FindAll()) { //ActiveDs.ADSearchres.Properties
5
3372
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 I could better understand the concept, he was trying to convey to me. I ran my own example and it crashed and burn "what a surprise!" : (. I ran the authors example out of the book and quess what, it crashed also, : 0. I ran them both on my...
8
1466
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 help to proceed. Looking for early reply. Amartya
13
3523
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 get the "UserName" of a connection. How is it possible? plz hlp thnk u
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.