第一個項目命名爲:命名空間EDSDKLib,然後類:公共類SDKHandler:IDisposable的如何在不同命名空間的同一解決方案中的兩個項目之間傳遞變量?
這個類裏面我有一個方法:
public void DownloadImage(IntPtr ObjectPointer, string directory)
{
EDSDK.EdsDirectoryItemInfo dirInfo;
IntPtr streamRef;
//get information about the image
Error = EDSDK.EdsGetDirectoryItemInfo(ObjectPointer, out dirInfo);
string CurrentPhoto = Path.Combine(directory, dirInfo.szFileName);
//create a filestream for the image
Error = EDSDK.EdsCreateFileStream(CurrentPhoto,
EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.ReadWrite, out streamRef);
uint blockSize = 1024 * 1024;
uint remainingBytes = dirInfo.Size;
//download the image data in blocks
do
{
if (remainingBytes < blockSize) { blockSize = (uint)(remainingBytes/512) * 512; }
remainingBytes -= blockSize;
Error = EDSDK.EdsDownload(ObjectPointer, blockSize, streamRef);
} while (remainingBytes > 512);
//download the last bit of the image
Error = EDSDK.EdsDownload(ObjectPointer, remainingBytes, streamRef);
//tell the camera that the download is done
Error = EDSDK.EdsDownloadComplete(ObjectPointer);
//release image and stream
Error = EDSDK.EdsRelease(ObjectPointer);
Error = EDSDK.EdsRelease(streamRef);
}
一旦圖像被下載到硬盤I想要使用一個bool變量還不確定在EdsRelease行之後的DownloadImage方法中。 例如,一個bool變量將被稱爲Saved,最後將其設置爲true:Saved = true;
然後我有另一個項目。 這個項目命名空間是:WinFormsUI和主窗體:公共部分類MainForm:表格
在這種形式,我想檢查另一個項目中的保存布爾變量。 例如,以秒爲間隔運行計時器,並檢查變量Saved it true是否爲每秒。
一旦這是真的停止計時器做一些事情,並再次設置變量保存爲假,並再次啓動計時器。
這是應該的樣子在MainForm中,我認爲:
private void timer1_Tick(object sender, EventArgs e)
{
if (Saved == true)
{
timer1.Stop();
// Do something
Saved = false;
timer1.Start();
}
}
的問題是如何傳遞和使用項目之間的保存變量。 所以我可以檢查它在MainForm中是否爲真,當我在MainForm中將它設置爲false時,它也會在EDSDKLib中生效,因此它也不會在那裏保持爲真。
這兩種項目類型是什麼?如果其中一個是類庫,則可以在WinForms項目中引用它。如果它們都是可執行文件,則需要使用某種IPC(進程間通信)機制。 – PoweredByOrange
EDSDKLib項目是類庫,第二個是winforms。 –