获取 Project Professional 中的活动缓存发送到 Project Server 队列系统的指定作业的状态。 只读 PjCacheJobState。
语法
expression。 GetCacheStatusForProject
expression:表示 Application 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 |
|---|---|---|---|
| ProjectName | 必需 | String | 项目名称;可以是活动项目,也可以是打开的其他项目。 |
| ProjectJobType | 必需 | PjJobType | 可以是保存、发布或检查操作的 PjJobType 常量之一。 |
备注
使用 Project Professional 执行使用 Project Server 中队列方法之一的操作(例如保存更新、发布或签入项目)时,Project Professional 缓存会向 Project Server 队列系统发送作业请求。 GetCacheStatusForProject 属性公开该队列作业的状态。
示例
以下示例中的 TestCacheStatus 宏保存活动项目,调用 WaitForJob 以等待队列成功完成,然后发布项目。 WaitForJob 宏通过调用 GetCacheStatusForProject 定期检查作业状态,并将作业状态打印到“即时”窗口。 如果连续发现十次以上相同的状态, WaitForJob 宏会假定存在问题并退出。 该示例使用的 Sleep 方法可以在 64 位 Project 安装或 32 位 Project 安装中运行。
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 支持和反馈,获取有关如何接收支持和提供反馈的指南。