Vista exception in .NET application "Exception handling message"

Background

I created a VB.NET application on the 4.0 Framework, part of the main functionality is the built-in AxWMPLib.AxWindowsMediaPlayer, which allows us to transfer the file path as the URL for the player and then play it through the built-in media player. My development platform is VS 2010 Pro for Windows 7.

Problem

We recently switched to testing this application on several operating systems. The application works fine on Win 7 on several win7 computers, some of which are used by other developers. The problem is that we are running the application on Vista. the first time the application tries to play the file after opening it, it gives an error

enter image description here

He does this most often, but not always, and I was not able to install the template several times when it did not cause an error. In addition, he does this only for the first file, which he does not play for subsequent files. And he escapes catch attempts to handle errors.

Study

I have done a lot of research on this issue. I found that it looks like other people's media players and websites, even WMP on some machines. Some articles point to specific Windows KB updates; others suggest starting a repair disk to restore potentially dangerous DLLs. I tried many of them unsuccessfully, as the problem persists on two Vista machines that I have to test with.

The code

here is the method that is called when this error occurs
Public Sub playSelected(ByVal fileStr As String) If File.Exists(fileStr) Then Debugging.DebugPrint(" Play: " & fileStr) MediaPlayer.URL = fileStr Try MediaPlayer.Ctlcontrols.play() Catch ex As Exception MessageBox.Show("Could Not play the selected File please try again. Exception : " + ex.Message) End Try Else Debugging.DebugPrint(" File Does not Exist: " & fileStr) End If End Sub 

Appointment

I hope to find a way to deal with this exception with code, potentially previewing or wearing it out if it is removed from one of the .NET controls that I use. I would rather handle this with code, if possible. If someone also has additional information about this particular error, that would also be welcome.

Resolution

Thanks to jornare for the information and push in the right direction, I will explain my decision and the code behind it below, I hope this helps.

At first I had to change the recommended answer in several different ways. The next two lines are declared in the class that calls the playSelected method above.

 Public Declare Function SetErrorMode Lib "kernel32.dll" (ByVal uMode As System.UInt32) As System.UInt32 Private Const SEM_FAILCRITICALERRORS As System.UInt32 = &H1 

you will see the addition of a Const variable with the name SEM_FAILCRITICALERRORS, this is necessary to set the variable to 1, in this case the variable name is very specific, since it corresponds to the var var name in the SetErrorMode method, when set to true, this flag disables the display of critical errors. I also added the dll file to the lib call, although it may not be needed.

Below is my new playSelected method

 Public Sub playSelected(ByVal fileStr As String) If File.Exists(fileStr) Then If isVista Then oldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS) End If Debugging.DebugPrint(" Play: " & fileStr) MediaPlayer.URL = fileStr Try MediaPlayer.Ctlcontrols.play() Catch ex As Exception MessageBox.Show("Could Not play the selected File please try again. Exception : " + ex.Message) End Try If isVista Then criticalFailureTimer.Interval = 2000 criticalFailureTimer.AutoReset = False criticalFailureTimer.Start() End If Else Debugging.DebugPrint(" File Does not Exist: " & fileStr) End If End Sub 

now it is important! Initially, I SetErrorMode returned to oldErrMode after calling ctlcontrols.play, but found that this did not stop the error. I installed my VS in debug mode on my win7 computer and walked through the code line by line. I found that the code did not actually try to play the file until it ended. This is why you see timer calls. I set a 2 second timer to give myself a buffer so that it could start the gameplay with the error mode set correctly. Below is the code that I used for the past timer event

 'in my Constructor If My.Computer.Info.OSFullName.Contains("Vista") Then isVista = True AddHandler criticalFailureTimer.Elapsed, AddressOf criticalTimerExpired End If 'end of Constructor portion Private Sub criticalTimerExpired(sender As Object, e As ElapsedEventArgs) SetErrorMode(oldErrMode) End Sub 

The last warning I will give for this. This process for my understanding disables critical errors from displaying, so be careful, in my case I could not find any specific error or system instability caused by the created error, so I temporarily disabled it to add to the usability of the program. I do not recommend doing this every time you have a system error, so often that the error indicates a deficiency / error in the program that needs to be fixed. In addition, in my opinion, you will never have to permanently disable critical errors, which means that you will definitely return them when you are done. I hope this information helps and appreciates the time and knowledge of those who answered or raised the question of voting.

+8
windows exception windows-vista
source share
1 answer

From what I find on the network, this can be caused by a faulty WMP plugin, codec, or display drivers. It was also discovered that you should resolve this error by calling the Windows API SetErrorMode function (SEM_FAILCRITICALERRORS) before WMP starts downloading the media file.

So for Vb something like:

 'declare Private Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long 'call it Dim oldErrMode As Long oldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS) 'Do your stuff here 'Set it back SetErrorMode(oldErrMode ) 

I have not tested this, so let me know if this helps.

+2
source share

All Articles