|
Hi,
Thanks for your reply
I used this code but it is still showing error highlighting fThread.Interrupt() ---Object reference not set to an instance of an object.Now what changes should I do in order to make this code work
[code]
private void frameExtract()//function to extract frames
{
string outPath = txtExtBitmap.Text;
System.IO.Directory.CreateDirectory(outPath);
if (fg != null)
{
foreach (FrameGrabber.Frame f in fg)
{
using (f)
{
picBoxFrame.Image = (Bitmap)f.Image.Clone();
f.Image.Save(System.IO.Path.Combine(outPath, "frame" + f.FrameIndex + ".bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
Application.DoEvents();
}
if (fg == null)
{
return;
}
}
}
}
public void ThreadProc()
{
try
{
MethodInvoker mi = new MethodInvoker(this.frameExtract);
this.BeginInvoke(mi);
}
catch (ThreadInterruptedException e)
{
Console.WriteLine("Interruption",e);
}
catch (Exception we)
{
Console.WriteLine("Exceptiom",we);
}
}
private void button43_Click(object sender, EventArgs e)//Extract button
{
fThread = new Thread(new ThreadStart(ThreadProc));
fThread.IsBackground = true;
fThread.Start();
}
private void button44_Click(object sender, EventArgs e)//Stop Button
{
fThread.Interrupt();
fThread = null;
}
[\code]
|
|
|
|
|
Payam Rastogi wrote: I used this code but it is still showing error highlighting fThread.Interrupt() ---Object reference not set to an instance of an object.
Of course! fThread only exists inside your button43 Client handler. The variable can't be seen anywhere else in your code.
And why are you calling Interrupt?? Inside your looping thread code you would check for a flag that says it should stop. You shouldn't be abruptly stopping the thread before it can do any cleanup work it needs to.
|
|
|
|
|
This is always a problem with long running synchronous (blocking) event handlers.
The easiest way of the top of my head:
Add a background worker component and set WorkerSupportsCancellation to true then call RunWorkerAsync() in the button_Click event handler. Put the code above in the DoWork event handler, then you can check the CancellationPending on each iteration.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
How could I show the total interest paid and the average interest gained each year?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project1
{
class Program
{
public static void Main()
{
Console.Write("Enter principal: ");
decimal p = Convert.ToDecimal(Console.ReadLine());
if (p < 0)
{
Console.WriteLine("Principal cannot be negative");
p = 0;
}
Console.Write("Enter interest rate: ");
decimal i = Convert.ToDecimal(Console.ReadLine());
if (i < 0)
{
Console.WriteLine("Interest cannot be negative");
i = 0;
}
Console.Write("Enter time (in years): ");
int years = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPrincipal = " + p
+ "\nInterest = " + i + "%"
+ "\nTime = " + years + " years\n");
Console.WriteLine("\n\nYear\tRate\t Amount\tInterest\tNew Amount");
Console.WriteLine("===========================================================");
int year = 1;
while (year <= years)
{
decimal interestPaid = p * (i / 100);
decimal amount = p + interestPaid;
p += interestPaid;
p = decimal.Round(p, 2);
interestPaid = decimal.Round(interestPaid, 2);
amount = decimal.Round(amount, 2);
Console.WriteLine(year + "\t" + i + "%\t" + ((p - interestPaid).ToString().PadLeft(10)) + "\t" + interestPaid.ToString().PadLeft(8) + "\t" + p.ToString().PadLeft(8));
year++;
}
}
}
}
|
|
|
|
|
yes
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I don't think the other answer you got really fit the question.
ctreed728 wrote: How could I show the total interest paid and the average interest gained each year?
By referring to your course notes, talking to your teacher if you get stuck, stepping through the code if you need to, and breaking down the task into small steps you can turn into code.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hi All,
I'm just working on a WPF desktop database app and I may have a scenario that I think could benefit from the occasional forced garbage collection. The only reason I'm really venturing down this path is that my user base are pretty savvy types and memory is *always* at a premium.
When the app starts up it's consuming around 50Mb of RAM nothing to complain about. However, during certain searches on the database this memory usage can escalate to 150Mb+. Say search 1 returns 60,000 records from the Db and in this scenario the memory jumps to 150Mb and a short time later another seach might only return a few hundred samples. I'm seeing the memory still at around the 150Mb mark whereas I want this to be immediately reduced to reflect the required RAM needed to represent that smaller search result set.
Is it worth exploring a forced GC.Collect() . I've been doing plenty of reading and it seems like the message is a little mixed on this. Some people seem to use it regularly, some say never use it. Microsoft seem to say leave it up to the CG to decide, but as I illustrated above I want to free that RAM as quickly as possible.
Thanks,
|
|
|
|
|
Jammer wrote: Is it worth exploring a forced GC.Collect().
Unless you really know what you're doing and why, no, it's not.
Jammer wrote: memory jumps to 150Mb and a short time later another seach might only return a few hundred samples. I'm seeing the memory still at around the 150Mb mark
Don't tell me you used TaskManager to determine this! It's lying to you. TM doesn't show you how much memory your app is actually using - it's showing you how much the .NET CLR has allocated to your app - including the rest of the managed heap that your app isn't using. Use PerformanceMonitor and the .NET Memory counters to see your apps actual usage.
You really don't have to worry about memory unless your app is really hanging onto it and not releasing it back to the managed pool. The .nET CLR does a very good job of managing the memory and returning whatever it can back to Windows, whenver Windows needs it.
Allocating object out of the managed pool is always faster than waiting for the CLR to get another block of memory from Windows, adding it to the Managed Heap, then allocating your object. That's why the CLR maintains a pool of memory that your app hasn't used yet.
Jammer wrote: but as I illustrated above I want to free that RAM as quickly as possible.
You don't have to. It's handled automatically whenever the CLR determines that is has an excessive amount of unused memory in the managed pool or Windows needs it back.
|
|
|
|
|
Dave Kreskowiak wrote: Unless you really know what you're doing and why, no, it's not.
Well, I obviously don't!
Dave Kreskowiak wrote: Don't tell me you used TaskManager to determine this! It's lying to you.
I did ... my bad!
Dave Kreskowiak wrote: Use PerformanceMonitor and the .NET Memory counters to see your apps actual usage.
Ok, will look into this now. I blatantly didn't do enough reading on this. Thanks for this input Dave, much appreciated.
Cheers,
|
|
|
|
|
I didn't mean to be nasty to you.
It's the third time this week I've had to describe how the .NET memory manager works. Everyone thinks that TaskManager is the "end all be all" of memory statistics, when it's not. Noone ever remembers that PerfMon even exists let alone that it can tell you FAR more about what's going on, and more accurately.
The last time I described this, the person didn't believe that TM could lie so badly. "yeah, TM is telling you that the app is using 100MB+ of RAM, but PerfMon says it's really using 18MB." Which one are you going to believe?
|
|
|
|
|
Dave Kreskowiak wrote: Big Grin I didn't mean to be nasty to you.
Hey Chap,
I didn't think you were. I've only been a .NETter for a little over a year and have a STACK ('scus the pun!) to learn yet.
I totally appreciate your input.
Cheers,
|
|
|
|
|
Dave Kreskowiak wrote: The .nET CLR does a very good job of managing the memory and returning whatever it can back to Windows, whenver Windows needs it.
I'm afraid this is not true in WPF. It SHOULD be, but it's not.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hardly the CLR's fault though. I think it's more WPF being sloppy under the hood. I've only touched on WPF here and there. Simple forms and controls really. I haven't had the time with a 1 year old running around the house to do much of anything new. But, teaching him stuff has turned out to be alot more fun than WPF teaching me how to pull my hair out!
|
|
|
|
|
I am CG. I think you want to force GC. Doing so, can make the number in the task manager lower, and while it's not accurate, WPF is also crap at this, you get no dispose methods and if you swap a lot of images, memory will leak and your app will crash.
Jammer wrote: Microsoft seem to say leave it up to the CG to decide,
OK, well, no-one ever calls me, so I really don't get to decide at all.....
They say that, but it's a lie. In winforms, yes. WPF sucks, and it's just unavoidable that you need to do it yourself. In fact, I found recently that running 20 odd video thumbnails in repeat mode, never reloading them, would cause a memory crash pretty quick. It's a joke.
GC.Collect();
GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
That's the magic code that I use. Without it, all my WPF apps would fail, for memory issues.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Christian Graus wrote: I am CG.
heh heh ...
Christian Graus wrote: I think you want to force GC. Doing so, can make the number in the task manager lower, and while it's not accurate, WPF is also crap at this, you get no dispose methods and if you swap a lot of images, memory will leak and your app will crash.
I've not seen any crashes as a result of this, nor has anyone reported crashes that might be related to memory but I think you might be right. I'm going to use PerfMon for a while and get a better idea of the real state of things with and without a forced GC.
Christian Graus wrote:
GC.Collect();
GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
Will have a read up on this, Thanks GC ... oops!
|
|
|
|
|
Jammer wrote: Thanks GC ... oops!
*grin*
Yeah, if you're not moving a lot of video or images about, you should be fine, and I'd still advocate not calling this code until you need to. But, we were ready for beta and this code turned our crashing mess into an app that works.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Christian Graus wrote: Yeah, if you're not moving a lot of video or images about, you should be fine, and I'd still advocate not calling this code until you need to. But, we were ready for beta and this code turned our crashing mess into an app that works.
Gotcha.
I've worked on two WPF apps now and haven't seen anything like this. However, I've not been working with bitmaps or video, only audio.
Thanks for the code snippet.
Cheers,
|
|
|
|
|
I have three unknowns..
float hours;
float minutes;
float seconds;
I use them to draw correct pointers, which are refreshing all the time.
Now i want to know how to retrieve elapsed seconds, minutes and hours from timer start to write them in those three unknowns all the time for drawing??
|
|
|
|
|
see timespan
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I created a program to capture the video from 4 cameras, would have access to the live image from the Internet, What is the best way to view the Internet.
|
|
|
|
|
Alex_xso wrote: What is the best way to view the Internet
Open a web browser??
Alex_xso wrote: I created a program to capture the video from 4 cameras, would have access to the live image from the Internet,
Are you saying that you want to view the live video over the Internet?? In that case, you would need a streaming server, such a Microsoft's Windows Media Encoder[^]. Then you just provide links to the streams exposed by that server. The streams will open up in Media Player on the client machines.
|
|
|
|
|
Any example?
|
|
|
|
|
Don't have any. If you're using webcams, then you just need to setup the Media Exocding Server once. You wouldn't need a code example for something you do by hand.
|
|
|
|
|
How does one have mdichildren forms automatically sized to fit the parent form?
My situation is I may have 5 to 10 child form at once and I would like to see all at once.
I'm developing in C# in Visual Studio 2005
Any and all suggestion are appreciated.
Thanks
|
|
|
|
|
If I recall correctly you have to set a property in the parent called MdiLayout
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|