Project) (Application.GetCacheStatusForProject 屬性
取得Project 專業版中作用中快取傳送至 Project Server 佇列系統之指定作業的狀態。 唯讀的 PjCacheJobState。
語法
expression。 GetCacheStatusForProject
expression 代表 Application 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
ProjectName | 必要 | 字串 | 專案的名稱;可以是使用中專案或開啟的不同專案。 |
ProjectJobType | 必要 | PjJobType | 可以是儲存、發佈或簽入作業的 PjJobType 常數之一。 |
註解
當您使用Project 專業版執行使用 Project Server 中其中一個佇列方法的作業,例如儲存更新、發佈或簽入專案時,Project 專業版快取會將作業要求傳送至 Project Server 佇列系統。 GetCacheStatusForProject屬性會公開佇列作業的狀態。
範例
下列範例中的 TestCacheStatus 宏會儲存使用中專案、呼叫 WaitForJob 等候佇列順利完成,然後發佈專案。 WaitForJob宏會藉由呼叫GetCacheStatusForProject定期檢查作業狀態,並將作業狀態列印到 [即時運算] 視窗。 如果連續找到相同的狀態超過十次, WaitForJob 宏會假設發生問題並結束。 此範例使用 可 在 64 位專案安裝或 32 位 Project 安裝中執行的 Sleep 方法。
Option Explicit
#If Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongLong)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
' Save and publish the active project; wait for the queue after each operation.
Sub TestCacheStatus()
Const millisec2Wait = 500 ' Number of milliseconds to sleep between status messages.
Application.FileSave
If WaitForJob(PjJobType.pjCacheProjectSave, millisec2Wait) Then
Debug.Print "Save completed ..."
Application.Publish
If WaitForJob(PjJobType.pjCacheProjectPublish, millisec2Wait) Then
Debug.Print "Publish completed: " & ActiveProject.Name
End If
Else
Debug.Print "Save job not completed"
End If
End Sub
' Check the cache job state for a save, publish, or check-in operation.
Function WaitForJob(job As PjJobType, msWait As Long) As Boolean
' Number of times the same job status is repeated until WaitForJob exits with error.
Const repeatedLimit = 10
Dim jobState As Integer
Dim previousJobState As Integer
Dim bail As Integer
Dim jobType As String
#If Win64 Then
Dim millisec As LongLong
millisec = CLngLng(msWait)
#Else
Dim millisec As Long
millisec = msWait
#End If
WaitForJob = True
Select Case job
Case PjJobType.pjCacheProjectSave
jobType = "Save"
Case PjJobType.pjCacheProjectPublish
jobType = "Publish"
Case PjJobType.pjCacheProjectCheckin
jobType = "Checkin"
Case Else
jobType = "unknown"
End Select
bail = 0
If (jobType = "unknown") Then
WaitForJob = False
Else
Do
jobState = Application.GetCacheStatusForProject(ActiveProject.Name, job)
Debug.Print jobType & " job state: " & jobState
' Bail out if something is wrong.
If jobState = previousJobState Then bail = bail + 1
If bail > repeatedLimit Then
WaitForJob = False
Exit Do
End If
previousJobState = jobState
Sleep (msWait)
Loop While Not (jobState = PjCacheJobState.pjCacheJobStateSuccess)
End If
End Function
以下是狀態訊息之間 500 毫秒的等候時間輸出。 如果網路延遲較大,請設定較長間隔的等候時間。 若要尋找輸出值的意義,請參閱 PjCacheJobState 列舉。 例如,值 4 是 pjCacheJobStateSuccess 常數。 如果您在未對專案進行任何變更時執行 TestCacheStatus ,儲存作業狀態會重複多次為 -1,也就是 pjCacheJobStateInvalid 常數的值。
Save job state: 4
Save completed ...
Publish job state: -1
Publish job state: 3
Publish job state: 3
Publish job state: 4
Publish completed: WinProj test 1
屬性值
PJCACHEJOBSTATE
另請參閱
PjCacheJobState 列舉PjJobType 列舉
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。