0
私が始めようとする前に、これは本当に私がやりたいことではないことを言及する必要があります。私はまた、別の方法を持っている 別のプロセスで使用されているファイルを削除するには?
public async void AddLayer()
{
try
{
// open a geodatabase on the local device
gdb = await Geodatabase.OpenAsync(@"..\..\..\test.geodatabase");
// get the first geodatabase feature table
var gdbFeatureTable = gdb.FeatureTables.FirstOrDefault();
//create a layer for the feature table
lyr = new FeatureLayer
{
ID = gdbFeatureTable.Name,
DisplayName = gdbFeatureTable.Name,
FeatureTable = gdbFeatureTable
};
// add the graphics to the map
MyMapView.Map.Layers.Add(lyr);
}
catch (Exception ex)
{
MessageBox.Show("Unable to create offline database: " + ex.Message);
}
return;
}
が
RemoveLayer()
と呼ばれる、単にすべて
AddLayer()
がしたし、その後のコール-UN行います
私は、ローカルジオデータベースファイルを開き、それを持つマップを作成AddLayer()
と呼ばれるこの方法を、持っていますGC.Collect()
。
私の質問は、ファイル内のリソースを使い切ってガベージコレクタを呼び出した後でも、プログラム実行中にファイル(ジオデータベースファイル)を削除できないのですか?
Windowsのすべてのプログラムでこれが正常に行われていますか?何とかプログラムを壊すのを避けるのですか?
ご理解いただきありがとうございます。その後、ジオデータベースから作られた、すべてがnullに設定、基本的に
public void OpenGeodatabase()
{
Geodatabase gdb = null;
// path to .geodatabase
var gdbPath = @"..\..\..\test.geodatabase";
// wrap OpenAsync call in Task
Task.Run(async() =>
{
// open a geodatabase on the local device
gdb = await Geodatabase.OpenAsync(gdbPath);
}).Wait();
// get the first geodatabase feature table
var gdbFeatureTable = gdb.FeatureTables.FirstOrDefault();
// create a layer for the feature table
var lyr = new FeatureLayer
{
ID = gdbFeatureTable.Name,
DisplayName = gdbFeatureTable.Name,
FeatureTable = gdbFeatureTable
};
// add the graphics to the map
MyMapView.Map.Layers.Add(lyr);
// remove the layer - to make it similar to case explanation
MyMapView.Map.Layers.Remove(lyr);
// make gdb reference null
gdb = null;
gdbFeatureTable = null;
lyr = null;
// call garbage collector
GC.Collect();
GC.WaitForPendingFinalizers();
// If the works, the lock has been removed
System.IO.File.Delete(@"..\..\..\test.geodatabase");
}
私は、タスク内のOpenAsyncへの呼び出しを非非同期メソッドの内部にすべて包まれました:
'async void'を使用しないでください。 – SLaks
私は 'gdb'がメンバ変数であると仮定しています。開いている操作の結果は、開いているファイルハンドルがどこにあるかということでしょう。それについてもっと多くのことやそれを処分する方法を知らなくても、具体的に何ができるかを言うのは難しいです。 –