|
Hi,
Anybody can help me to solve this problem.
I trying to open a powerpoint file(for preview) in my application using AxFramerControl.
axFramerControl1.Open(fileName, true, "PowerPoint.Show", null, null);
.....
.....
axFramerControl1.Close();
It is opening the file in my application, but after closing the file i am trying to delete the file.
File.Delete(filename);
In this case i am getting an error "Cannot delete access denied". i think it is problem with axFramerControl1.Close(), it is not closing the application properly. Can anybody tell me how to close the Framercontrol correctly to delete the file.
thanks in advance
Jafar K
|
|
|
|
|
Hi, I've recently started using Windows forms and need to create many threads which loop through a given CSV and process the contents to a method. I'm not sure of the best way of doing this. I can create a few threads but each thread processes each line rather than 1 line being processed by one thread and the next line being processed by another thread. The first value is a unique identifier if that helps.
Hope I've explained it ok, can anybody please advise?
Thanks
|
|
|
|
|
I would expect that one thread should read the file and place each line in a Queue. Then several other threads can read from the Queue and proceed from there.
|
|
|
|
|
Hi,
you could open a streamreader on the file, then launch a few threads all executing the same code, containing this pseudo-code:
while(!allDone)
lock the streamreader (or some other object)
read one line from the streamreader, and set allDone true if no more data available
unlock again
process the line read, if any
}
allDone is a bool, starting false, shared by all threads.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
modified on Sunday, January 31, 2010 10:44 PM
|
|
|
|
|
I'm just not convinced that that will yield a significant performance boost. And I suspect that decoupling the reading and processing will yield a more-maintainable system.
|
|
|
|
|
Neither am I, however the OP stated "need to create many threads", so I must assume those threads will be busy outside the lock most of the time, in which case I don't need code to read the entire file and pump it through a queue.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Thanks, but I'm new to this.
How do I go about locking my streamreader so each thread does a different line, etc?
Thank you
|
|
|
|
|
Hi,
not tested, you should read up on all classes and methods used, then adapt whatever needs adapted, and add error handling:
StreamReader sr;
bool allDone;
void handleFileWithManyThreads(string filename, bool waitTillDone) {
allDone=false;
sr=File.Open(filename);
List<Thread> threads=new List<Thread>();
for(int i=0; i<Environment.NumberOfProcessors; i++) {
Thread thread=new Thread();
thread.Start(runner);
threads.Add(thread);
}
if (waitTillDone) {
foreach(Thread thread in threads) thread.Join();
sr.Close();
}
}
void runner() {
while(!allDone) {
string line=null;
lock(sr) {
line=sr.ReadLine();
if (line==null) allDone=true;
}
if (line!=null) {
}
}
}
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Load the file contents into a list, and run the threads in a thread pool. When you queue the threads into the thread pool, assign an index into the list to the thread. Then, when a thread runs, it can simply retrieve the specified index item and be done with it.
I think it might be even better to queue just a handful of threads, assign a block of items to it (specifying the first and last index to process). This would save the time/resources associated with overhead regarding thread contexts and switching.
The thread pool will report itself ide when processing is complete, so you don't have to track the status/progress unless you really want to.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
If you're new to this, I think that the outlow programmers ideea is the best.
To make things even easier(not faster) you could use ParallelLINQ or the parallel task(s) library to process the datas from the list. This way you don't have to worry about threads, locks and other quite painfull stuff.
It's available as an extension/add on to .NET 3.5 SP1 and out of the box for .NET 4.0(soon to come).
|
|
|
|
|
Thank you very much for the replies.
I created 10 threads and broke down my file into 10 files. Each thread would loop through then.
This is what I went with in the end:
private void btnRun_Click(object sender, EventArgs e)
{
for (int i = 0; i < threadCount; i++)
{
CreateThread(i);
}
}
private void CreateThread(int threadID)
{
Thread thread = new Thread(new ParameterizedThreadStart(RunProcess));
thread.Start(threadID);
lstThread.Add(thread);
}
private void RunProcess(object threadID)
{
int id = (int)threadID;
for (int i = id; i < threadCount; i += threadCount)
{
ProcessByThread(Convert.ToInt32(threadID));
}
lstThread[id].Abort();
}
private void ProcessByThread(int threadNumber)
{
GetDataFromCsv("Batch" + threadNumber + ".csv", threadNumber);
}
|
|
|
|
|
what is wpf and where should i start?
|
|
|
|
|
Here[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
It's the Windows Presentation Foundation, and is the replacement for Windows Forms. It provides a much richer experience than Win Forms as it's not tied to GDI+, so it's possible to create animations, 3d work, etc... with a lot less work than you used to have to do.
If you want to look into this, there are several good books on WPF - the two standard ones are WPF Unleashed[^] by Adam Nathan and Pro WPF[^] by Matt Macdonald.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
hi everyone i have wrote two application by socket programing that connect to each other by ip the problem is that if listener program has an invalid ip(being in a local network) the other application can not access it i mean that i dont know how to connect to an application that is in a local network
please help me
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:49am.
|
|
|
|
|
hi thank u for your answer and i really appriciate that here is my codes:
|
|
|
|
|
i have a dll that contains WPF controls
i want to add them into a windows form project
how could i do that ?
i added the source to the solution
i didn't see the controls in the toolbox..what's next ?
|
|
|
|
|
That's because a WPF control can't be used in standard Windows form.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
In order to host WPF in Win Forms, you need to add an ElementHost to your form, e.g.
ElementHost host = new ElementHost();
host.Dock = DockStyle.Fill;
host.Child = myWpfControl; Obviously, you'd have to have instantiated myWpfControl before you add it to the host, but this is the general flow.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
i want to learn network programming in c#
can any body send be absolute beginning to network programming link
|
|
|
|
|
You might want to start with WCF.
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
i suggest you to start with socket programing
|
|
|
|
|
Try this book[^] it is supposedly aimed at beginners.
|
|
|
|
|
How do they work?
I'm having a hard time understanding them.
I've read up on several examples but the code approach just seems strange to me (I'm not a C/C++ programmer so I am not used to function pointers).
Can delegates be compared to Java's addActionListener(new MyHandler());?
If they can, then it would help me understand this far better.
Basically, in Java you add an event handler (java.awt.event.*) to an object (e.g. a button)
and then you tell it that when an action happens on that button (such as being clicked),
said method will be assigned to handle it (MyHandler).
Implemented, it looks like this:
myButton.addActionListener(new MyHandler());
class MyHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
doStuff();
}
}
To my analogy, this would compare to C# like this:
myButton.Click += new System.EventHandler(MyHandler);
public void MyHandler(Object o, EventArgs e)
{
doStuff();
}
So as far as I understood, a delegate delegates the task of doing something, to
a method that has the same signature as the delegate.
What about System.EventHandler(MyMethod) then?
Is one passing a method to EventHandler() as an argument
or is MyMethod replacing EventHandler by its signature?
Do I have to take callback functions in account to understand delegates?
I'm still confused, but I will read up on it (even though I've read a lot about delegates).
Thanks for reading.
Treval
|
|
|
|