|
Hello everyone,
I'd like to describe thoroughly my current scenario but it'd get a little bit verbose and perhaps misleading.
Let's say the main thread is queuing items to load and another thread should be loading asynchronously these items.
My main question is about the performance of creating and disposing of several FileStream objects, used to load files asynchronously several times in a row.
If you were to create a producer/consumer queue bound to async load files from hard-disk, how would you go? Would the disposal and creation of FileStream objects be of concern for you?
Thanks in advance!
Rob
|
|
|
|
|
You will be bound by the disk I/O at that point, so it will depend on how much work your doing with that stream. It might make more sense to use a memory stream and when your done, quickly dump that to disk.
I'd probabyl use MSMQ for my process list and have an external service pick up those messages to do the processing. Using MSMQ allows you to seperate out the functions of accepting work and doing work. The messages will also be persisted during failures by MSMQ, so it also gives you a safe guard.
I haven't looked at it much atall, but I think WCF can use MSMQ for it's message delivery medium. If you decide to go the route of seperating the processes, take a look at WCF as the communication mechanism.
|
|
|
|
|
Hi,
It has already been said that disk I/O will most likely be your performance bottleneck anyway, making object allocation / garbage collection a non-issue from a performance point of view.
However, disposing of file streams is in my experience often critical - as the physical file will stay open (and possibly locked) until the stream is disposed (or Close()d, which is equivalent if I remember correctly - either of them kills the Win32 file handle). Unless you're the only one touching the files, this can cause problems. I routinely wrap any file I/O in using blocks when possible, in order to minimize file lock durations.
In similar scenarios I usually just enqueue what needs to be done in a Queue<my_job_type> and dequeue it from a worker thread (locking the Queue when enqueuing or dequeueing). Usually I use a Queue<my_result_type> for the results from the worker thread.
Note: The normal restriction on only locking private stuff applies, of course. Your queues should not be visible outside of your class - if people in other classes (as would be expected) enqueue things to do and dequeue results, you wrap those operations (and queue lengths or HasWorkToDo and HasResults properties or whatever feels appropriate) in methods and properties of your own class. User code calls your en-/dequeueing methods (which use lock blocks), not the ones of the actual Queues.
I usually raise an event as well whenever I have enqueued stuff to the results queue, but beware that naïve users of your class may run into problems when they touch UI stuff from the event handler if they forget to Invoke() them properly (as the event will be raised from another thread than the UI thread). You should document that if your class isn't strictly internal.
Later,
--
Peter
|
|
|
|
|
First, thanks for your feedback.
I realize I've been a bit too vague in my initial post; however your suggestions reflect what I initially suspected.
Let me clarify a bit. I'm currently working on a 3D game and I've created a texture loader using the producer / consumer queue pattern. Depending on the view distance and the player position, I load and unload landscape textures from hard disk. I assumed (wrongly) that loading textures from another thread would be non-blocking for the main thread; this was not the case, since upon testing I was experiencing hiccups.
In another forum I read that perhaps an asynchronous loading would generally perform better (i.e. no hiccups). Seeing as I'm bound to load many textures per loader usage, I was curious to know about the performance of FileStream objects. I know they have to be correctly disposed; I'm not sure how the loader would behave when there are many concurrent asynchronous locks - if there's such a thing.
I know some testing would pretty much answer, but I thought that having some feedback, some first-hand experience on the matter would save me some time (which is never enough!).
Thanks again for any further advice,
Rob
PS: For any of you interested, some game screenshots can be found in the Gallery section of www.darkmana.com[^]
|
|
|
|
|
we'll be making an appointment schedulling for doctors.. it should display a table:
columns - doctor's name
rows - time slots
everytime we'll enter a new appointment, it will be displayed in the table.. can somebody help us??
|
|
|
|
|
sorry, whats the exact problem?
Tiefe Brunnen muss man graben wenn man klares Wasser will,
tiefe Wasser sind nicht still.
|
|
|
|
|
how can we make that appointment table?
|
|
|
|
|
hi mjee,
I think you want to store doctor Name and Appointment time in each row.If am i right,then make a table(in databsse) which contains the column DoctorName(Text Type) and AppointmentTime(Date time Type)
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
do you want to show it like a matrix?
| Dr. 1 | Dr. 2 | Dr. 3 |
...
09:00 | Mr. 1 | ---- | ----- |
09:30 | ----- | Mr. 2 | ----- |
...
Der Staat mit der niedrigsten Geburtenrate ist nicht die Bundesrepublik, sondern der Vatikan.
|
|
|
|
|
You can make a class the inherits from DataTable:
and make an initializing method where you put som ething like
TableName = <tablename>, add columns and dump to xml.
you can load it next time, and put it as GridView datasource.
|
|
|
|
|
Can I suggest you start out by having a good think about your database. It is the core of any application like this and unless you get this bit right early on you will struggle to enhance the system.
To get you started I would initially approach this with 3 tables.
Doctor
======
DoctorId - INT - NOT NULL - IDENTITY - PRIMARY KEY
DoctorName - NVARCHAR(200) - NOT NULL
(You can add other columns here later as needed)
Surgery
=======
SurgeryId - INT - NOT NULL - IDENTITY - PRIMARY KEY
SurgeryName - NVARCHAR(200) - NOT NULL
(Other columns here too eg/ opening times)
Appointment
===========
AppointmentId - INT - NOT NULL - IDENTITY - PRIMARY KEY
DoctorId - INT - FOREIGN KEY (Doctor)
SurgeryId - INT - FOREIGN KEY (Surgery)
AppointmentDateTime - DATETIME
(Other columns here if necessary)
That should get you started on the Db structure, and easily allows you to pull out all records for a particular doctor, or surgery, to display in a grid.
|
|
|
|
|
hi
I m developing a desktop application in streaming media using C#.
I m doing different opertions in it using multithreading like User Login, searching information from Database, searching and playing video file etc.
I m also capturing Live video from Webcam and displaying it on the window of my application. But the problem is that when I put the code of Live video capturing and preveiwing in Thread,it doesn't work i.e it doest not caputer n display the live video.
so tell me that is multithreading not possible in streaming media or there is some techniques of multithreading for it?
Plz reply me ASAP
Regards
B!z
|
|
|
|
|
its possible, but you have to ensure threadsafety, say, by using a circular buffer or similiar.
Hope this helps, Good luck
|
|
|
|
|
I'm coding a program like this in .Net 3.0. When you load a XML data. Its elements, texts, attributes will be populated on the Tree View and its full content in Text Box. I used XDocument(System.Xml.Linq) to make it faster. But now When I select a node from the Tree View, I want to highlight the line of XML code in the Text Box which contain that node. Any solution for this ? Help me, pls. Thank you.
modified on Friday, May 16, 2008 2:01 AM
|
|
|
|
|
Personally I would make a class that inherits from TreeNode and store the corresponding XML Code in it. When you select this TreeNode you can search in the Textbox for that string an highlight it.
Hope this helps
Tiefe Brunnen muss man graben wenn man klares Wasser will,
tiefe Wasser sind nicht still.
|
|
|
|
|
Thanks for your help. I thought about it and I found one problem. If two element has the exact name, attribute and text. How can I distinguish between them. I don't know how to store and retrieve their full path. Can you make an example for me
|
|
|
|
|
If two elements have the same name, you can distinguish it by the order of the elements. Have these elements the same parent?
I could only give you an example with the standard XmlDocument object. With linq i didn't handle that problem yet.
Tryout the XmlNotepad from MS, may this gives you an idea, how you can handle the Xml.
Der Staat mit der niedrigsten Geburtenrate ist nicht die Bundesrepublik, sondern der Vatikan.
|
|
|
|
|
Thank you, I will give it a shot
|
|
|
|
|
Hi Guys. Is there any other function or method I can use to return a 16 digit number? I have very large numbers that I am trying to calculate and the problem is that I am usi8ng LONG and Int64 at the moment and I only get a 13 digit value returned instead of the full 16 digits.
Does anybody have any ideas or advice?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I don't think anything is built in, but the libraries do exist, I am sure
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks mate. I have read a few articles but can't make head or heels from them. Have been looking ata few on Codeproject like this one http://www.codeproject.com/KB/cs/biginteger.aspx[^] but they don't seem to be much help though. Have googled around and can't find anything. Old languages like Oracle and Cobol can handle this, why not C#?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Perhaps people had more money back then ? :P
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Heck, Java has a BigInteger type built in. Came in handy when I was doing some RSA stuff for my internship.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Yeah, I'm sure they did. Well, lets put it this way,I have a file generated on our DEC, in COBOL which then calculates a range of numbers to create a HASH total. Problem is that the file generated only caters for 12 digits in the layout and we can't get this changed as it is a regulatory file layout. I need to recalculate this hash total so I can verify it with the third party that process the file. So, I'm a bit stuck. I have tried to calculate this in Excel 2007 but Excel 2007 seems to be doing some sort of automatic rounding for some strange reason which left me with trying to develop something in C# to do this instead.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
A long/Int64 can handle at least 18 digits.
An alternative would be to use the Decimal data type. That will give you at least 28 digits.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Friday, May 16, 2008 2:29 AM
|
|
|
|