Printing a batch of documents (images) at once - c#

I'm currently working on an application that is supposed to automatically print parsed images from a batch and have the batch refill itself when the batch becomes empty as long as the program is set to do so (user-input).
I've gotten as far as to get the images printed properly one by one through user input, but I can't seem to find any decent solution to printing several images at once without the interface locking up.
The idea I thought of myself was to either prepare the printerspool with an X amount of jobs at once and then invoke the Print() method to have the printer handle it from there or to append all the images into one document and send it as a single job. Then I also need to know the status of every card in the print-batch.
What can I do to make this happen? Thanks in advance!

I suggest, you simply put your printing code in a background thread, e.g. using BackgroundWorker.

Related

Best way to read and write time-critical data?

I have .txt files that are overwritten with data from software every 5-10 seconds, I then have a wpf application that reads and displays this data every second. Here are my issues:
Currently the text files are stored on a server and there are a bunch of users running this application to view this "live" data.
HOWEVER, due to:
An I/O bug in windows
The files "lock" up periodically and cause all of the applications to lock up (can't even close in task manager).
Therefore I decided to have the data copied from the text files to SQL, however from my understanding there's no way to overwrite the data in the SQL table. One must Drop the Table and Create a new one. This cause a 10+ second delay updating the data, which cannot happen.
My question is, there HAS to be a way to rapidly read and write data from somewhere, be it a database, etc. I am not sure where else to turn.
My constraints:
I'm stuck with Server 2008, have to use these text file, and I have to display it on my wpf application. Does anyone have any suggestions for a method that can handle this type of I/O?
All help is greatly appreciated, I'm at a complete loss..
It seems like you may not have extensive experience with database technology, so let me propose something different:
string text = System.IO.File.ReadAllText(path);
Then perhaps you can take the text and do what you want with it, dump it in a queue for action in another part of the application.
ReadAllText has some exceptions that are thrown:
https://msdn.microsoft.com/en-us/library/ms143368(v=vs.110).aspx
I'd be on the look out for UnauthorizedAccessException as you said, the file seems to lock up when multiple users are accessing it.

Best way (best performance) to lock file creation

I have a web application to return images to my frontend.
In this application what happens is: when a request is made to a particular image the application checks if the image already exists on disk; if it exists the image is returned.
My problem starts when the image does not exist on disk. In that case two requests are made at the same time for the same image which does not exist on disk. Problem occurs when two threads try to create the same file on disk at the same time.
To solve the problem, what I tried to do was to create a Mutex in the creation of disk image. But it had a problem: as the server load is enormous due to the large number of simultaneous requests, the server crashes.
I would like to ask what your ideas to solve this problem. Or what you would do otherwise?
Thank you.
You could try the following pattern:
Try to read the image (if succeeds, than done)
Try to create the image with Write lock
Only on "File in use exception", small delay (milliseconds)
Go back to step 1 (retry)
Make the delay really small, just a tiny bit larger than the time it should need to create an image.
Implement a retry limit, max 3 times or so.
This would allow you to make use of the already existing (file) locking mechanism
You can call the open function with O_CREAT and O_EXCL flags. The first process's open call will get exclusive access to create the file and it will start downloading the image. The subsequent process's open call will fail because their open is not exclusive and "errno" will be set to EEXIST.
Based on your design, the subsequent processes can either wait for complete file creation or can return back.
fd = open(path, O_CREAT|O_EXCL)

text exchange between two processes on a box using Memory Mapped File

Requirement is to be able to achieve 'chat' like communication between two console apps on the same windows box. I implemented this using named pipes, by implementing both a sender and receiver functionality in each app.
I want to try the same functionality but using Memory Mapped files (though I think it is not ideal for 'chat' type communication).
For simplicity sake, say chat messages are just strings of short length.
Here is what I have in mind:
One app will take care of creating a mutex and the memory mapped file.
Call it master.
In each app, we maintain two threads, one responsible for taking user
input and writing to the file, the other responsible for periodically
checking if it has something to read.
So four threads in all, each governed by a mutex for access to the
file.
Within the file, I think both should have their own 'section'. say
first half of the file size is for master app and the other half for
the second app.
So when user inputs a line of text in master app, the thread accesses
its half of the file and tries to append new text after the last new
line.
When app reads its section of the file for text, if there is any, app
reads it and blanks out its section.
Is this approach correct? Other approach would be to some how mark the message with the source id, so that the reader knows to ignore messages that are written by itself. But I feel that is unnecessary string parsing.
Also, other than each reader thread periodically trying to read their section of the file to see if there is new data, can you suggest any kind of notification mechanism? Sort of event handling? Reader thread will only go look for new messages if it gets some kind of event notification.
Any thoughts?
I agree with Hans for the most part, memory mapped files would not nessecarily be ideal here, if you go down this road though consider using a named event (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396(v=vs.85).aspx) instead of polling.
You may need to p/invoke to get at this functionality from c#.
On the rest give each app its own region of the file, with a control section managed by the master to coordinate who gets what.

powerpoint record rehearsal timings

Does anyone know how to set powerpoint's record slideshow/rehearsal timings using c# or VB? Can it be done in the open xml files? Or what developer references am I overlooking? I want to be able to choose a different method for timing up a self running presentation.
Here's code to add a 2 1/2 second rehearsal Timing to Powerpoint
slide.SlideShowTransition.AdvanceTime =2.5f;
slide.SlideShowTransition.AdvanceOnTime = MsoTriState.msoTrue;
Took me forever to find this, so hoping it helps others
Happy Programming!
AdvanceTime is stores the duration of the whole slide the event trigger time is stored in tag.xml file as Timing the values are stored as a pipe delimiter values like '|34.0|34|3|5.4'

c# DirectShow graphbuilder output filename issue

I'm new to using Directshow. I'm more than willing to post the pages of code I've writen but I'm hoping someone could explain or hint in the right direction for a solution so I can figure it out myself.
Basically I have a WPF program that displays a window that has a preview of my webcam - this is done and working. Now I'm trying to get it to record the preview - done using graphBuilder.SetOutputFileName
However everytime I show the window to record another session is just overwrites the last file it recorded, even though I'm calling graphBuilder.SetOutputFileName again!
So my question is how can I change the outputfilename to record a second video. I know I'm missing something but don't know what.
Thanks in advance.
Rich
Filter graphs normally create media files starting from scratch on your initial Run and closing the file on your Stop. Next time you repeat the calls, you just start it from fresh from empty (overwritten) file. There is no appending. If you want to keep the previously recorded content, you need to switch files by providing new name, or copying/renaming the completed file.

Categories

Resources