Пример #1
0
            public bool RequestTaskState(TaskState state, TimeSpan timeout)
            {
                var waitForStart = false;
                var currentState = TaskState.Unknown;

                try
                {
                    lock (TaskStateLock)
                    {
                        currentState = TaskState;

                        if (!task.CanRequestTaskState(state))
                        {
                            throw new InvalidOperationException("Can't enter TaskState" + state);
                        }

                        if ((state == TaskState.Starting || state == TaskState.Running) &&
                            TaskState != TaskState.Starting && TaskState != TaskState.Running &&
                            TaskState != TaskState.Paused && TaskState != TaskState.Waiting)
                        {
                            Start(timeout);

                            waitForStart = true;

                            return(true);
                        }

                        if (Thread.CurrentThread == TaskThread)
                        {
                            if (TaskState == state)
                            {
                                return(true);
                            }

                            SetRequestedTaskState(state);

                            ProcessTaskStateRequest();

                            return(true);
                        }

                        if (timeout != TimeSpan.Zero)
                        {
                            if (TaskState != state)
                            {
                                while (true)
                                {
                                    SetRequestedTaskState(state);

                                    Monitor.PulseAll(TaskStateLock);

                                    if (HasAquiredTaskState(state))
                                    {
                                        SetRequestedTaskState(TaskState.Unknown);

                                        break;
                                    }

                                    if (!Monitor.Wait(TaskStateLock, timeout))
                                    {
                                        return(false);
                                    }
                                }
                            }

                            return(true);
                        }
                        else
                        {
                            if (TaskState != state)
                            {
                                SetRequestedTaskState(state);
                            }

                            return(true);
                        }
                    }
                }
                finally
                {
                    if (waitForStart && timeout != TimeSpan.Zero)
                    {
                        this.task.WaitForAnyTaskState(timeout, PredicateUtils.ObjectNotEquals(currentState));
                    }
                }
            }
Пример #2
0
 /// <summary>
 /// Returns the name part of a URL
 /// </summary>
 /// <param name="uri"></param>
 /// <returns></returns>
 public static string GetName(string uri)
 {
     return(uri.SplitAroundCharFromRight(PredicateUtils.ObjectEqualsAny <char>('/', '\\')).Right);
 }
Пример #3
0
 public static string RemoveQuery(string uri)
 {
     return(uri.Left(PredicateUtils.ObjectEquals <char>('?').Not()));
 }
Пример #4
0
 public static Pair <string, string> SplitAroundCharFromRight(this string s, char c)
 {
     return(s.SplitAroundCharFromRight(PredicateUtils.ObjectEquals(c)));
 }