using System.Threading.Tasks;
[...]
try
{
Task executeTask = STask.Factory.StartNew(() => DoSomething());
//Wait for 5 minutes
int index = System.Threading.Tasks.Task.WaitAny(new[] { executeTask },
TimeSpan.FromSeconds(300));
if (index == -1)
{
//Task execution Time Out
}
else
{
//Task executed in-time
}
}
catch (AggregateException aex)
{
foreach (Exception ex in aex.InnerExceptions)
LogError(ex, ex.Message);
}
catch (Exception ex)
{
LogError(ex, "Error");
}
giovedì 20 dicembre 2012
Controllo del timeout su un Task
Ci sono molti modi per verificare se l'esecuzione di un task si conclude entro un periodo di timeout.
Questo è il più semplice ma non per questo meno efficace:
domenica 2 dicembre 2012
Menu da Web.sitemap con separatori
Se si usa il file Web.sitemap per generare automaticamente le voci di menu in Asp.net, si nota subito che tutte le voci sono raggruppate insieme e non è possibile inserire un separatore. Utilizzando il codice di seguito, invece, è possibile.
Nel file Web.sitemap (per ogni node dopo il quale si vuole inserire il sepratatore):
Nel codice:
Nel file Web.sitemap (per ogni node dopo il quale si vuole inserire il sepratatore):
Nel codice:
Protected Sub Menu1_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemDataBound
If e.Item.Text.IndexOf("[sep]") > 0 Then
e.Item.Text = e.Item.Text.Replace("[sep]", "")
e.Item.SeparatorImageUrl = Page.ResolveUrl("~/Common/images/dividerhoriz.gif")
End If
Try
If Menu1.SelectedItem Is Nothing Then
If IsNodeAncestor(CType(e.Item.DataItem, SiteMapNode), System.Web.SiteMap.CurrentNode) Then
If e.Item.Selectable Then
e.Item.Selected = True
End If
End If
End If
Catch ex As Exception
'Exception management
End Try
End Sub
'''
''' Determines if a is the ancestor of a second one.
'''
''' The to analyze.
''' A which may or may not be
''' the 's child.
''' true , if the two nodes are related, false otherwise.
Private Function IsNodeAncestor(ByVal ancestor As SiteMapNode, ByVal child As SiteMapNode) As Boolean
Dim result As Boolean = False
Try
If Not ancestor.ChildNodes Is Nothing AndAlso ancestor.ChildNodes.Contains(child) Then
Return True
Else
If (Not child.ParentNode Is Nothing) AndAlso (Not ancestor Is child.RootNode) Then
Return IsNodeAncestor(ancestor, child.ParentNode)
End If
End If
Catch ex As Exception
'Exception management
Return False
End Try
Return result
End Function
Protected Sub SiteMapPath1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SiteMapNodeItemEventArgs) Handles SiteMapPath1.ItemDataBound
If Not e.Item.SiteMapNode Is Nothing Then
If e.Item.SiteMapNode.Title.IndexOf("[sep]") >= 0 Then
Try
e.Item.SiteMapNode.Title = e.Item.SiteMapNode.Title.Replace("[sep]", "")
Catch
'Exception management
End Try
End If
End If
End Sub
sabato 1 dicembre 2012
Fonti per file multimediali
Ho deciso di inserire un post di riferimento per chunque (me compreso) abbia bisogno di foto, clipart, audio, musica o video. Aggiornerò questo post quando troverò nuove risorse.
Icone, Immagini e Foto
The Noun Project
http://thenounproject.com
IconFinder
http://www.iconfinder.com
Icons 8
http://www.icons8.com/
The XAML Project
http://www.thexamlproject.com/
SyncFusion Metro Studio
http://www.syncfusion.com/downloads/metrostudio
266 Icons
http://raphaeljs.com/icons/
Windows 8 App Icons
http://codefoster.com/win8icons
morgueFile
http://www.morguefile.com
iStockphoto
http://www.istockphoto.com
Corbis
http://www.corbis.com
Open Game Art
http://opengameart.org
Audio
freesound.org
http://www.freesound.org/browse
Incompetech
http://incompetech.com/music/royalty-free
Video
Ancora niente...
Icone, Immagini e Foto
The Noun Project
http://thenounproject.com
IconFinder
http://www.iconfinder.com
Icons 8
http://www.icons8.com/
The XAML Project
http://www.thexamlproject.com/
SyncFusion Metro Studio
http://www.syncfusion.com/downloads/metrostudio
266 Icons
http://raphaeljs.com/icons/
Windows 8 App Icons
http://codefoster.com/win8icons
morgueFile
http://www.morguefile.com
iStockphoto
http://www.istockphoto.com
Corbis
http://www.corbis.com
Open Game Art
http://opengameart.org
Audio
freesound.org
http://www.freesound.org/browse
Incompetech
http://incompetech.com/music/royalty-free
Video
Ancora niente...
Iscriviti a:
Commenti (Atom)