Winform没有关闭为什么?

时间:2016-05-12 14:02:09

标签: vb.net winforms

我有一些代码可以保存我的FormClosing事件中的日志,该事件正常工作,直到我添加代码来创建目录,如果它不存在这样的目录。

现在,如果我添加注释行,则应用程序不会关闭。

我不明白为什么。

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

//and create new timer with async call:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    [locationManager startUpdatingLocation];

    NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(startTrackingBg) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] run];
});

}
 -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
//  store data
CLLocation *newLocation = [locations lastObject];


//tell the centralManager that you want to deferred this updatedLocation
if (_isBackgroundMode && !_deferringUpdates)
{
    _deferringUpdates = YES;
    [locationManager allowDeferredLocationUpdatesUntilTraveled:CLLocationDistanceMax timeout:10];
}
}

1 个答案:

答案 0 :(得分:2)

问题在于目录的字符串格式,对目录和文件都使用PathArchivo,而实际上只需要为目录创建创建没有文件名的目录:

Dim PathDir As String = Application.StartupPath & "\Logs" 'use only directory string here
Dim PathArchivo As String = Application.StartupPath & "\Logs\" & Fecha & ".logout" 'note that this is file name with .logout extension
If (Not System.IO.Directory.Exists(PathDir)) Then 'creates directory without .logout
    System.IO.Directory.CreateDirectory(PathDir)
End If
RTB_Log.SaveFile(PathArchivo, System.Windows.Forms.RichTextBoxStreamType.RichText)    

请注意,您的PathArchivo是一个logout扩展名为

的文件路径