I'm working on converting some of my ArcMap addins to work in Pro. Rather steep learning curve given that is no ESRI guidance at all on doing this.
I have found that you can't do anything with geodatabases without wrapping it into an asynchronous function. I managed to find some sample code and wrote a test addin that lists all the featureclasses in a geodatabase.
The code below actually works, but is really messy with the inline defined "lambda" function. I should be able to clean it up with a separate function as in the commented out lines in the code, but am having trouble properly constructing the code.
The IDE tells me QueuedTask.run wants an "action" and not the function I passed it, so I don't know where to go from there.
I also found that I needed to add "async" to the addin button's onclick override to make it work, but that was a shot in the dark as none of the documentation or samples showed this, so I don't know if this is the proper way to do it.
Friend Class Sample
Inherits Button
Dim m_gdbPath As String = "F:\HIES\CnmiImagery\CnmiImagery.gdb"
Protected Overrides Async Sub OnClick()
Dim strMsgs As String = ""
Try
'strMsgs += Await QueuedTask.Run(getDefs())
strMsgs += Await QueuedTask.Run(Function()
Dim msg As String = ""
Using gdb As New Geodatabase(New FileGeodatabaseConnectionPath(New Uri(m_gdbPath, UriKind.Absolute)))
Dim defs As IReadOnlyList(Of TableDefinition) = gdb.GetDefinitions(Of FeatureClassDefinition)()
For Each fdsDef As FeatureClassDefinition In defs
msg += fdsDef.GetName & vbCrLf
Next
End Using
Return msg
End Function)
Catch ex As Exception
MsgBox(ex.Message)
End Try
MsgBox(strMsgs)
End Sub
'Function getDefs() As String
' Dim msg As String = ""
' Using gdb As New Geodatabase(New FileGeodatabaseConnectionPath(New Uri(m_gdbPath, UriKind.Absolute)))
' Dim defs As IReadOnlyList(Of TableDefinition) = gdb.GetDefinitions(Of FeatureClassDefinition)()
' For Each fdsDef As FeatureClassDefinition In defs
' msg += fdsDef.GetName & vbCrLf
' 'Console.WriteLine(TableString(fdsDef As TableDefinition))
' Next
' End Using
' Return msg
'End Function
End Class<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>