|
I post there but no one answer it. thanks
|
|
|
|
|
You did get responses, there.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
|
I can't for the life of me figure out how to access the region from a tick thread which is calling a bgworker().
Here is the original code
private void t_processFrame_Tick(object sender, EventArgs e)
{
if (!_bw_frameProcessor.IsBusy)
{
_bw_frameProcessor.RunWorkerAsync();
}
}
private void _bw_frameProcessor_DoWork(object sender, DoWorkEventArgs e)
{
try
{
GetImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
g = Graphics.FromImage(GetImage);
g.CopyFromScreen(screen.Bounds.X, 0, 0, 0, GetImage.Size);
pbDesktopFeed.Image = (Bitmap)GetImage;
motionDetector.ProcessFrame((Bitmap)pbDesktopFeed.Image);
}
catch (Exception ex) { }
}
Its kind of frustrating because I have been sitting here for 3 days (I have a high tolerance of trying different variations before I burn myself out) trying to figure out why it works fine in Timer_Tick but not when Timer) Tick is running the Backgroundworker. My guess is that it is because of the Threads between the both.
I have tried cloning the bitmap inside the background worker
GetImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
Bitmap clone = (Bitmap) GetImage.Clone()
g = Graphics.FromImage(clone);
g.CopyFromScreen(screen.Bounds.X, 0, 0, 0, clone.Size);
pbDesktopFeed.Image = (Bitmap)GetImage;
motionDetector.ProcessFrame((Bitmap)pbDesktopFeed.Image);
I have tried cloning the image using AForge:
GetImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
g = Graphics.FromImage(GetImage );
g.CopyFromScreen(screen.Bounds.X, 0, 0, 0, GetImage .Size);
pbDesktopFeed.Image = (Bitmap)GetImage;
motionDetector.ProcessFrame(AForge.Imaging.Image.Clone((Bitmap)pbDesktopFeed.Image));
This however, works fine when I drop it all into the Timer_Tick event.
private void t_processFrame_Tick(object sender, EventArgs e)
{
try
{
GetImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
g = Graphics.FromImage(GetImage);
g.CopyFromScreen(screen.Bounds.X, 0, 0, 0, GetImage.Size);
pbDesktopFeed.Image = (Bitmap)GetImage;
motionDetector.ProcessFrame((Bitmap)pbDesktopFeed.Image);
}
catch (Exception ex) { }
}
|
|
|
|
|
It's probably pretty simple: only code that is running on the main (UI) thread can access any control in any way: since you moved it to a BackgroundWorker it isn't running on that thread any more, so when you try to access the Image or similar it's failing with an exception. Start by adding a try...catch block with Debug.WriteLine statements to check that and consider either Invoking the relevant controls or moving the Control related code back to the UI thread via the Progress reporting mechanism of the BackgroundWorker.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Turns out it was as simple as creating a public void PreviewImageUpdate() outside of the bg worker
private void t_processFrame_Tick(object sender, EventArgs e) {
if (!_bw_frameProcessor.IsBusy) {
_bw_frameProcessor.RunWorkerAsync();
}
}
private void _bw_frameProcessor_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
_bw_frameProcessor.Dispose();
}
private void _bw_frameProcessor_DoWork(object sender, DoWorkEventArgs e) {
UpdateMotionDetectionPreview();
}
public void UpdateMotionDetectionPreview() {
try {
GetImage = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
g = Graphics.FromImage(GetImage);
g.CopyFromScreen(screen.Bounds.X, 0, 0, 0, GetImage.Size);
if (motionDetector.ProcessFrame(GetImage) > 1.02 f)
pbDesktopFeed.Image = GetImage;
else
pbDesktopFeed.Image = GetImage;
} catch (Exception ex) {}
}
However, I do plan to take consideration in using a ScreenCaptureScreen() to relay this image to AForge video player to improve the over performance of the framerate since the PB update is too slow.
|
|
|
|
|
I have a C# solution with multiple projects in it:
- Project 1 = A Windows Service project (with an app.config file containing general settings, to be used by ALL projects; this project will be the "main" startup project of the solution)
- Project 2 = A class library containing classes and functions that will handle execution of business logic (and do some logging in the EventViewer)
Upon startup, the Windows Service should read contents of its app.config [THIS WORKS!!!]
- Project 3 = A WinForm Test application that I temporarily use to test the business logic execution and logging.
Ultimate goal is to "remove" Project 3 and have the Windows service handle the business logic/logging.
In the app.config, I enter the settings that will be used by both project 1 and 2. Is there a simple way to "share" the config settings across all projects in the entire solution (upon startup of the service)?
I can create a GeneralConfig class, and add some properties, but how can I make this object (with the current properties) common to all projects. Is there something like a "single-instance" object.
Dox Girl, where are you?
|
|
|
|
|
Take a look at TopShelf[^] and you won't need the separate Test application project.
It's a console "wrapper" around your service, allowing you to run the app either as a console application or as a service, in a single executable.
|
|
|
|
|
A very simple way to eliminate Project 3 while debugging is to alter the Main function in the Program.cs file.
An example is:
private static void Main(string[] args)
{
if (!Environment.UserInteractive)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ControlLoop()
};
ServiceBase.Run(ServicesToRun);
}
else
{
// Establish the foreground run...
MainThread objMainThread = new MainThread(false);
MainThread.Run(objMainThread);
}
}
In this case, MainThread is the name of your top level service class that contains your Run function. This is generally called from the ControlLoop.Onstart event...
|
|
|
|
|
I have been studying, and experimenting (in WinForms), with the newer structures (.NET 5.0) Vector, Rect, and Point in System.Windows (requires WindowsBase.dll). They offer some useful extended functionality compared to the Point/PointF and Rectangle/RectangleF structures in System.Drawing. They're Double based, so they will play nicely with the result of Math operators like Sin, Cos, Pow.
I intend to rewrite the 2d geometry library I am developing using those structures, and, when ready, publish it here; if you have used these structures, how have you found memory use and performance ?
thanks !
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Hello.
I have a forms application in C# and Visual Studio. Tis app interacts with Excel and is workin fine.
I installed the executable and the configuration file in another computer and whe the app calls excel I received a message stating that a library was not registered. The error message says that it's not possible to convert a COM object type 'System.___ComObjet' into the interface 'Microsoft.Office.Interop.ExcelApplication'.
Does anyone know what to do to correct it? Which DLL should be copied too?to correct it? Which DLL should be copied too?
|
|
|
|
|
Perhaps you're suggesting that in order to run your app on a computer that does not have VS installed, copy the C:\Program Files\Microsoft Visual Studio #.0 (your version)\VC\redist content to that computer. Just a thought. If the app runs then ytou can start worrying about whether this is legal or not.
Lookup MSVCR and where to download it from Microsoft. That should do it.
[EDIT POST 16pt hit]
You mention a library ... what library?
[/EDIT]
modified 26-Aug-21 12:16pm.
|
|
|
|
|
It means that the system does not have the Interop.Excel libraries installed. As far as I am aware you can only get these by installing a legal version of Excel on the system.
|
|
|
|
|
Hi, Richard. The excel is legal. So, what should I do? Which files should I copy?
|
|
|
|
|
The interop libraries should be installed automatically with Excel. On my system I have the following:
Microsoft.Office.Core: C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll
Microsoft.Office.Interop.Excel: C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll
The versions on your system may be different, but the dll files should still be there.
It would also appear that Microsoft make them available for download at Download Microsoft Office 2010: Primary Interop Assemblies Redistributable from Official Microsoft Download Center[^].
|
|
|
|
|
Richard.
Ok, I found these files in my computer. Now I will see if they are in the other computer.
Thanks.
|
|
|
|
|
Richard.
I checked the other computer and those files are there and are the same. I don't know what to do. If you have any suggestion, I would appreciate it.
|
|
|
|
|
Sorry Ismael, I have never encountered this problem, so I have no suggestions. You could try a Google search, or one of the Microsoft support sites.
|
|
|
|
|
No problem, Richard. You've helped me anyway. 
|
|
|
|
|
What version of Office is installed on the other computer?
|
|
|
|
|
It's version 2013. Do you think it makes difference?
|
|
|
|
|
You have to have Microsoft Excel, or Office, installed on the machine. Interop doesn't mean you get the functionality without the app. It means it's an "interoperability" interface between your app and the app you're trying to use in it, like Excel.
|
|
|
|
|
|
Try reinstalling Excel on the problem machine.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
We just change netcore to framework and it works
Hello,
We have a WS, if you go to server you can run it and see the 2 methods, you can invoke then and WORK
If you go to Visual Studio 2019 and add a reference to the project using the: http://xxx.xxx.xxx.x/wsxxx/wseps.asmx?wsdl you can see the method and add to the project:
But when we try:
ServiceReference1.WPSSOAPCLIENT oClient= new ServiceReference1.WPSSOAPCLIENT()...
1. The new ServiceReference1.WPSSOAPCLIENT() is marked as an error.: Does not contanins a constructor that take 0 argument
modified 24-Aug-21 10:16am.
|
|
|
|