|
If you're looking for a control to automatically handle the Drag and Drop for you AND/OR display a PDF for you without any work on your part, in either case, there is no such thing.
|
|
|
|
|
Hi loaded multiple files in web browser
But when I load image , image size is not fitScale in webbrowser . But pdf drag in same webbrowser it fitScale window and preview full screen.
If I use image width and height in webbrowser then image image was fitScale in webbrowser window.
But I can’t load in same webbrowser window pdf
|
|
|
|
|
I don't have a clue what you're talking about.
You offer up no context about anything. We have no idea what kind of app you're writing (Windows Forms, WPF, ASP.NET/MVC, ...), what problem you're having, how this "web browser" and "fitScale" stuff figures into your app, ... nothing makes any sense.
|
|
|
|
|
I am using Windows application Web browser control
1. in my winforms i have 9 webbrowser control each web browser control load all files
eg: image, pdf, word excel
2. now in my winforms webbrowser control loading image when i drag and drop image in webbrowser1 the image size is not expand to webbrowser control window. i write this code for image expand to webbrowser control.
private void webbrowser1_DocumentCompleted(object sender,WebbrowserDocumentCompletedEventArgs e)
{
var img = webBrowser1.Document.GetElementsByTagName("img").Cast<htmlelement>().FirstOrDefault();
var w = img.ClientRectangle.Width;
var h = img.ClientRectangle.Height;
img.Style = string.Format("{0}: 100%", w > h ? "Width" : "Height");
}
after this code is expanding image in webbrowser1 control and preview full screen.
now i am trying to load pdf in Webbrowser1 show error
Object reference not set to an instance of an object.
|
|
|
|
|
That's because a PDF doesn't show in an IMG tag. Look at the page source HTML after the PDF loads.
|
|
|
|
|
"Which Control will Work for Acrobat Pdf in properties there is not DragDrop Event and DragEnter"
Not everything is exposed using properties. If you want to drag and drop from Shell/Explorer, then you have to start coding. Also, the type of file is not relevant; it works the same way for all files
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have install Shell? in Nuget? Please can share any link related Drag and Drop
|
|
|
|
|
|
Thanks will try this link and let you know
|
|
|
|
|
Weekend is approaching, and in case you may feel bored without a complicated programming task, I have a puzzle for you.
I already asked at StackOverflow: c# - Logging exceptions in fire&forget tasks - Stack Overflow[^], but did not get a usable answer.
In short, I want to create a method which takes an Action parameter, fires off a Task with it, and makes sure that exceptions do not crash the application (but logs the exception messages so that I can find out that something bad happened).
I tried following code:
public static void CreateAndStartTaskWithErrorLogging(Action _action, string _componentName, string _originalStacktrace = null)
{
DateTime started = HighPrecisionClock.Now;
Task task = new Task(_action);
task.ContinueWith(_continuation => _continuation.LogExceptions(_componentName, started, _originalStacktrace));
task.ConfigureAwait(false);
task.Start();
}
internal static void LogExceptions(this Task _t, string _componentName, DateTime _started, string _originalStacktrace = null)
{
try
{
_t.Wait(1000);
}
catch (Exception ex)
{
Logger.LogError(_componentName, $"An exception occurred in a fire-and-forget task which was started at {_started}.\r\n" +
$"The original stack trace is:\r\n{_originalStacktrace}");
Logger.LogException(_componentName, ex);
}
try
{
_t.Dispose();
}
catch (Exception dex)
{
Logger.LogException(_componentName, dex);
}
}
Well, normally, it works.
Normally.
Not always...
And then the service crashes with an error entry in the Windows Event Log.
(That's also true for the solution in the first answer at SO).
Some more background.
The application is a highly configurable Windows Service. The function is called with Utilities.TaskExtensions.CreateAndStartTaskWithErrorLogging(() => DataStore.StoreSyncedData(data), Name); , where DataStore is set to a composite which in turn calls Parallel.ForEach(m_InnerDataStores, _store => { _store.StoreSyncedData(_syncedData); }); on its members. One of them writes a video with the Accord library, which sometimes causes an AccessViolation at <Module>.avcodec_encode_video2(libffmpeg.AVCodecContext*, libffmpeg.AVPacket*, libffmpeg.AVFrame*, Int32*) , i.e. the exception may come from non-managed code. Perhaps 10% of these exceptions evade...
So my question is:
how should my function look like to catch those evading exceptions?
And extra upvotes if you can explain why my code (or the suggested solution at SO) fails.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Thanks for raising the level of discourse
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Native exceptions thrown by unmanaged code that occured on a thread started by that unmanaged code can't be caught. That's most often originating from a COM-object.
Bernhard Hiller wrote: the exception may come from non-managed code. Upvote is for you, as you answered it before me
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: Native exceptions thrown by unmanaged code that occured on a thread started by that unmanaged code can't be caught. Thanks for that hint. Since most of these exceptions are caught by the catch, that seems unlikely (the stack trace, regardless if logged by my logger or the Windows Event Log, shows always the same function, i.e. these are not different kinds of exception, only different instances of the same exception).
So, what are the circumstances that let 1 out of 10 of these exceptions evade?
Is it something in the Parallel.ForEach which may or may not use a different thread for the execution?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Bernhard Hiller wrote:
So, what are the circumstances that let 1 out of 10 of these exceptions evade?
Is it something in the Parallel.ForEach which may or may not use a different thread for the execution? No, more likely to be a thread by unmanaged code; avcodec_encode_video2 it was? Does it use DirectX?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
"Occurs when an exception is thrown in managed code" - that won't work here, since the exception is thrown in unmanaged code.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Bernhard Hiller wrote: and makes sure that exceptions do not crash the application
Depending on your definition of terms that is impossible in C#.
There are at least three exceptions which will cause a .Net AppDomain to exit and there is absolutely nothing you can do to stop it. One of those is the stack overflow exception. You can in fact 'catch' it but it will just keep going once the catch block exits. And it terminates the AppDomain not the process.
"Starting with the .NET Framework 2.0, you can't catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default."
StackOverflowException Class (System) | Microsoft Docs[^]
Now of course the workarounds for that depends on your definition.
1. Your main AppDomain (every process) could spin up a new AppDomain to do the actual launch. Then the 'application' can't exit only the new AppDomin will. Well at least not from this task.
2. Make sure the possible exceptions do not occur.
Bernhard Hiller wrote: And then the service crashes wi
For starters looks like you are missing try/catches and logging.
But other than that there can however be any number of reasons for that. For example consider the following scenario.
1. You have class A in DLL X.
2. You use A in your main service class in a method M()
3. You call M().
4. Nothing else in X is used until M() is called.
In the above X is not loaded until M() is called but it is loaded when M() is invoked.
Now if X is not available you are going to get an exception.
Something similar happens if you have a class C where attributes/implements uses C or where the methods have a return type or parameter that refers to C.
So the best 'safe' way to create a service is as follows.
Create a class, call it Everything, which does ALL of the functionality of the application. That means that the service class, the one with OnStart() does NOT do any application functionality.
The service class looks like the following pseudo code
class MyService
{
// It MUST be 'Object' and not 'Everything'
// There should be NO other attributes and NO
// other methods except ones that call directly
// to Everything.
Object instance
Logger logger = ...
OnStart()
{
try
{
instance = new Everything();
((Everything)instance).Start();
}
catch(Exception e)
{
logger.Error("Failed to start", e);
}
}
OnStop()
{
try
{
((Everything)instance).Stop();
}
catch(Exception e)
{
logger.Error("Failed to stop", e);
}
}
}
Of course even that is limited because 'Logger' is also a dependency that can fail to load.
|
|
|
|
|
Of course, there are some exceptions which cannot be caught. In the current scenario, about 9 out of 10 instances of that Exception are caught, which offers proof that it is not an uncatchable exception.
jschell wrote: For starters looks like you are missing try/catches and logging You missed the point. The try/catch is exactly one of the things the utility function should supply (and so it does).
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
You should read my example again. There are catchable exceptions that your current code will not catch because they can occur before the try catch that you coded is entered.
|
|
|
|
|
update: this bug occurs in VS 2019. and in the latest VS 2019 preview release ... however, after closing these IDE's when the error occurs, I don't see the collateral damage caused by VS 2017.
The song I am not hearing as I write this: [^]
like: "System.ComponentModel.Win32Exception was unhandled. Message="The parameter is incorrect" when you close a WinForm app after the run-time user changes the Opacity in a secondary Form (note: a Form with the 'Owner not set, instantiated and 'shown in main form code).
That's been around for many years, and typical strategies, like removing the EventHandlers that modify Opacity prior to closing the "Main Form," and/or disposing of secondary Forms ... don't work.
Okay: so what ? The unpleasant surprise is that not only does the latest Visual Studio Enterprise 2017 ... using VisualStudio.15.Release/15.9.13+28307.718 with Microsoft .NET Framework Version 4.8.03761 ... get trashed, but Win 10 1903 (latest regular flavor) gets the entire Desktop screwed up.
All the symptoms of some virus from hell. And, yes, I immediately did a full virus scan ... during this Win Defender scan, its major process, MsMpEng, took 75~90+% of CPU time ... that's running with "Normal" priority !
Is this "progress" ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 13-Jun-19 0:59am.
|
|
|
|
|
This wouldn't be the first time I've seen an app do some crazy sh*t to Windows 10.
Last summer, a certain application (can't say the name), completely fubar'd the Start button in Explorer. Click Start button and launch the app or launch it from the Desktop shortcut and so something very specific in the app, but commonly done, and the Start button in Explorer would no longer work. Click it and nothing would happen, no opening of the menu at all.
The fun part was once it was broken, there was no getting it back. The problem persisted through shutdowns and restarts. And the is an app used on thousands of machines! Thankfully, due to how this app gets tested and deployed into production, it only hit about 50 machines when it broke.
Narrowed it down to how a certain set of controls (10+ years old) was being registered on the machine AND in combination with a certain Windows 10 O/S patch. The problem disappeared a couple of months later, after another set of patches and we changed how the vendor registered the controls in their installation.
I just spent 3 months on another production problem with the same app. A certain patch broke functionality in the app where a datagrid didn't work as expected any more. I was still working on it when another set of patches came down and the grid magically started working again. W T F ?!
Spent the last 3 weeks going through testing of three months worth of patches to find the one that broke the grid and the one that fixed it. Turns out they were both Office 2013 patches that updated MS Common Controls. W T F v2 ?! CommonControls is used by millions of applications, not just Office, and MS decided to disguise updating what amounts to O/S patches as Office patches?! W T F v3?!
|
|
|
|
|
You're surprised that a MS patch broke your code - W T F v4!
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
No, I'm not.
It's not our code either. It's vendors code. If it was my code, I wouldn't be relying on old controls and Crystal Reports.
What I was surprised about what the disguising of what amounts to O/S patches as Office patches.
modified 13-Jun-19 16:31pm.
|
|
|
|
|
empathy is
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
How to find the processID of an IE Tab, from ShDocVw.InternetExplorer(ShDocVw.ShellDocs). The property HWND is same for all the tabs. Need a solution to find the processId of individual tabs.
|
|
|
|
|