2012-03-20 20 views
1

我正试图在互联网上找到一些相机相关教程。问题是,大多数教程都是用C#完成的,而我需要它在VB.NET。我曾尝试使用在线转换器转换它,但它并不总是识别所有的语法,因此我得到错误。如何将其转换为Visual Basic?如何将此方法从C#转换为VB.NET

Loaded += (_, __) => 
    { 
     Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = 
      Microsoft.Phone.Shell.IdleDetectionMode.Disabled; 

     cam = new VideoCamera(); 
     cam.Initialized += (___, ____) => 
      { 
       cam.LampEnabled = true; 
       cam.StartRecording(); 
      }; 
     vCam.SetSource(cam); 

     new Thread(() => 
      { 
       try 
       { 
        var isf = IsolatedStorageFile.GetUserStoreForApplication(); 

        var files = isf.GetFileNames(); 
        foreach (var file in files) 
        { 
         Debug.WriteLine("Deleting... " + file); 
         isf.DeleteFile(file); 
        } 
       } 
       catch (Exception ex) 
       { 
        Debug.WriteLine("Error cleaning up isolated storage: " + ex); 
       } 
      }).Start(); 
    }; 

这是我从转换器得到的代码:

Loaded += Function(_, __) 
Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = _ 
    Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

cam = New VideoCamera() 
cam.Initialized += Function(___, ____) 
cam.LampEnabled = True 
cam.StartRecording() 

End Function 

vCam.SetSource(cam) 

New Thread(Function() 
Try 
    Dim isf = IsolatedStorageFile.GetUserStoreForApplication() 
    Dim files = isf.GetFileNames() 
    For Each file As var In files 
     Debug.WriteLine("Deleting... " & Convert.ToString(file)) 
     isf.DeleteFile(file) 
    Next 
Catch ex As Exception 
    Debug.WriteLine("Error cleaning up isolated storage: " & ex) 
End Try 

End Function).Start() 

End Function 
+0

我使用了一个转换器,它的字面意思是给我错误无处不在 – Matt9Atkins 2012-03-20 00:31:05

+0

我建议发布转换器做了什么,所以人们可以帮助缩小错误。 – 2012-03-20 00:31:58

+0

我在转换器代码中添加了 – Matt9Atkins 2012-03-20 00:34:10

回答

0

使用Roslny。转换器在00分55秒出现。

PS:下划线对于变量名是一个坏主意。

+0

下划线用于命名从不被引用的函数参数,但他没有编写代码,所以他可能没有给它们命名。 – Gabe 2012-03-20 01:20:32

-1

使用下面的(我用Telerik Converter):

Loaded += Function(_, __) Do 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

    cam = New VideoCamera() 
    cam.Initialized += Function(___, ____) Do 
     cam.LampEnabled = True 
     cam.StartRecording() 
    End Function 
    vCam.SetSource(cam) 


    New Thread(Function() Do 
     Try 
      Dim isf = IsolatedStorageFile.GetUserStoreForApplication() 
      Dim files = isf.GetFileNames() 
      For Each file As var In files 
       Debug.WriteLine("Deleting... " + file) 
       isf.DeleteFile(file) 
      Next 
     Catch ex As Exception 
      Debug.WriteLine("Error cleaning up isolated storage: " + ex) 
     End Try 
    End Function).Start() 
End Function 

我希望这有助于:)

+0

Visual Studio中的各种错误:( – Matt9Atkins 2012-03-20 01:37:07

+1

我不认为+ =在添加事件处理程序时起作用,您应该使用AddHandler语句。 – 2012-03-20 13:36:31

0

你的转换器似乎不知道如何处理+ =运算符或下划线做VB。他们正在对编译器造成严重破坏。

变化

Loaded += Function(_, __) 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

AddHandler Loaded , Function(x as Object, y as Object) 
    Microsoft.Phone.Shell.PhoneApplicationService.Current.ApplicationIdleDetectionMode = _ 
     Microsoft.Phone.Shell.IdleDetectionMode.Disabled 

,改变

cam.Initialized += Function(___, ____) 

AddHandler cam.Initialized, Function(xx as Object, yy as Object) 

请注意,您可能需要更改事件处理程序中的Object签名以匹配实际的事件签名,但其他内容一眼就能看到。